Atlas › Test

TestInterrupt

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

Package
go.temporal.io/server/common/locks
Suite / test hierarchy
TestConditionVariableSuite/TestInterrupt
Test
TestInterrupt
Introduced at
condition_variable_impl.go ×1 Frontier kind: Joint frontier
Covered ranges
4
Covered lines
32
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 32 covered LOC · 4 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.
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:
78 // received signal
79 > case <-interrupt: condition_variable_impl.go
80 // interrupted
81 }
82 }
83
84 > func newCVChannel() chan struct{} { condition_variable_impl.go
85 > return make(chan struct{}, 1)
86 > }