Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.40 KB | None | 0 0
  1. func (b *Batcher) Load() interface{} {
  2.     b.mu.Lock()
  3.     defer b.mu.Unlock()
  4.  
  5.     if !b.first {
  6.         b.con.Wait()
  7.  
  8.         if !b.second {
  9.             b.con.Wait()
  10.         }
  11.  
  12.         b.second = false
  13.  
  14.         b.value = b.valueSlow.Load()
  15.         b.first = true
  16.         b.con.Broadcast()
  17.     }
  18.     b.first = false
  19.  
  20.     b.mu.Unlock()
  21.  
  22.     b.value = b.valueSlow.Load()
  23.  
  24.     b.mu.Lock()
  25.  
  26.     b.second = true
  27.     b.con.Broadcast()
  28.     b.first = true
  29.     return b.value
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement