Atlas › Test

TestBroadcast

Exact test identity: go.temporal.io/server/common/locks/TestConditionVariableSuite/TestBroadcast

Package
go.temporal.io/server/common/locks
Suite / test hierarchy
TestConditionVariableSuite/TestBroadcast
Test
TestBroadcast
Introduced at
TestBroadcast Frontier kind: Test frontier
Covered ranges
5
Covered lines
41
Covered files
1

Covered source

Expand a file to inspect source; the > gutter marks covered lines.

go.temporal.io/server/common/locks/condition_variable_impl.go 41 covered LOC · 5 ranges

Open complete file

18 func NewConditionVariable(
19 lock Locker,
20 > ) *ConditionVariableImpl { condition_variable_impl.go
21 > return &ConditionVariableImpl{
22 > lock: lock,
23 >
24 > chanLock: sync.Mutex{},
25 > channel: newCVChannel(),
26 > }
27 > }
28
29 // Signal wakes one goroutine waiting on this condition variable, if there is any.
40
41 // Broadcast wakes all goroutines waiting on this condition variable.
42 > func (c *ConditionVariableImpl) Broadcast() { condition_variable_impl.go
43 > newChannel := newCVChannel()
44 >
45 > c.chanLock.Lock()
46 > defer c.chanLock.Unlock()
47 >
48 > close(c.channel)
49 > c.channel = newChannel
50 > }
51
52 // Wait atomically unlocks user provided lock and suspends execution of the calling goroutine.
55 func (c *ConditionVariableImpl) Wait(
56 interrupt <-chan struct{},
58 >
59 > c.chanLock.Lock()
60 > channel := c.channel
61 > c.chanLock.Unlock()
62 >
63 > // user provided lock must be released after getting the above channel
64 > // so channel to be waited on < release of user lock < acquire of user lock < signal / broadcast
65 > // ```
66 > // That is, if another thread is able to acquire the mutex after the about-to-block
67 > // thread has released it, then a subsequent call to pthread_cond_signal() or
68 > // pthread_cond_broadcast() in that thread behaves as if it were issued after the
69 > // about-to-block thread has blocked.
70 > // ref: https://pubs.opengroup.org/onlinepubs/007908799/xsh/pthread_cond_wait.html
71 > // ```
72 >
73 > c.lock.Unlock()
74 > defer c.lock.Lock()
75 >
76 > select {
77 > case <-channel: condition_variable_impl.go
78 // received signal
79 case <-interrupt: