Skip to content

Commit 67f5c82

Browse files
committed
Lock the guard before checking the count.
Small race in the barrier. If the count was dropped to 0 before the lock was grabed in `fn signal()` the event would be missed.
1 parent 2cf38bf commit 67f5c82

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/barrier.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ impl Barrier {
5050

5151
impl Signals for Barrier {
5252
fn signal(&self) -> Signal {
53+
let mut guard = self.inner.trigger.lock().unwrap();
5354
let (p, t) = Signal::new();
5455
if self.inner.count.load(Ordering::Relaxed) == 0 {
5556
t.pulse();
5657
} else {
57-
let mut guard = self.inner.trigger.lock().unwrap();
5858
*guard = Some(t);
5959
}
6060
p

0 commit comments

Comments
 (0)