Permalink
Browse files

sync: Ensure try_send() wakes up receivers

This branch of try_send() just forgot to wake up any receiver waiting for data.

Closes #15761
  • Loading branch information...
1 parent e288fc6 commit 31eb00c022aba208921046cdec046f77a96ec98c @alexcrichton alexcrichton committed Jul 18, 2014
Showing with 26 additions and 1 deletion.
  1. +19 −0 src/libsync/comm/mod.rs
  2. +7 −1 src/libsync/comm/sync.rs
View
@@ -2098,4 +2098,23 @@ mod sync_tests {
});
assert_eq!(rx.recv(), 1);
} #[ignore(reason = "flaky on libnative")])
+
+ test!(fn issue_15761() {
+ fn repro() {
+ let (tx1, rx1) = sync_channel::<()>(3);
+ let (tx2, rx2) = sync_channel::<()>(3);
+
+ spawn(proc() {
+ rx1.recv();
+ tx2.try_send(()).unwrap();
+ });
+
+ tx1.try_send(()).unwrap();
+ rx2.recv();
+ }
+
+ for _ in range(0u, 100) {
+ repro()
+ }
+ })
}
View
@@ -218,9 +218,15 @@ impl<T: Send> Packet<T> {
}
} else {
// If the buffer has some space and the capacity isn't 0, then we
- // just enqueue the data for later retrieval.
+ // just enqueue the data for later retrieval, ensuring to wake up
+ // any blocked receiver if there is one.
assert!(state.buf.size() < state.buf.cap());
state.buf.enqueue(t);
+ match mem::replace(&mut state.blocker, NoneBlocked) {
+ BlockedReceiver(task) => wakeup(task, guard),
+ NoneBlocked => {}
+ BlockedSender(..) => unreachable!(),
+ }
Ok(())
}
}

9 comments on commit 31eb00c

Contributor

bors replied Jul 19, 2014

saw approval from kballard
at alexcrichton/rust@31eb00c

Contributor

bors replied Jul 19, 2014

merging alexcrichton/rust/issue-15761 = 31eb00c into auto

Contributor

bors replied Jul 19, 2014

alexcrichton/rust/issue-15761 = 31eb00c merged ok, testing candidate = 3f04dc1

Contributor

bors replied Jul 20, 2014

saw approval from kballard
at alexcrichton/rust@31eb00c

Contributor

bors replied Jul 20, 2014

merging alexcrichton/rust/issue-15761 = 31eb00c into auto

Contributor

bors replied Jul 20, 2014

alexcrichton/rust/issue-15761 = 31eb00c merged ok, testing candidate = 5e0a597

Contributor

bors replied Jul 20, 2014

fast-forwarding master to auto = 5e0a597

Please sign in to comment.