diff options
| author | bors <bors@rust-lang.org> | 2016-10-05 18:10:34 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-10-05 18:10:34 -0700 |
| commit | 46957f05771a427545c792f69b37f8e05dcbb15d (patch) | |
| tree | 3a5c600d8991777c6679b71a597e0d1b9f9819e6 /src/libstd/sync | |
| parent | 3210fd5c20ffc6da420eb00e60bdc8704577fd3b (diff) | |
| parent | fb90e4c7b69dec797d036dc0aac802d9b2a18198 (diff) | |
| download | rust-46957f05771a427545c792f69b37f8e05dcbb15d.tar.gz rust-46957f05771a427545c792f69b37f8e05dcbb15d.zip | |
Auto merge of #36893 - apasel422:issue-32114, r=alexcrichton
Restore `DISCONNECTED` state in `oneshot::Packet::send` Closes #32114 I'm not sure if this is the best approach, but the current action of swapping `DISCONNECTED` with `DATA` seems wrong. Additionally, it is strange that the `send` method (and others in the `oneshot` module) takes `&mut self` despite performing atomic operations, as this requires extra discipline to avoid data races and lets us use methods like `AtomicUsize::get_mut` instead of methods that require a memory ordering.
Diffstat (limited to 'src/libstd/sync')
| -rw-r--r-- | src/libstd/sync/mpsc/mod.rs | 7 | ||||
| -rw-r--r-- | src/libstd/sync/mpsc/oneshot.rs | 2 |
2 files changed, 9 insertions, 0 deletions
diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index d9c14ef2f77..6d37f160590 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -1940,6 +1940,13 @@ mod tests { // wait for the child thread to exit before we exit rx2.recv().unwrap(); } + + #[test] + fn issue_32114() { + let (tx, _) = channel(); + let _ = tx.send(123); + assert_eq!(tx.send(123), Err(SendError(123))); + } } #[cfg(all(test, not(target_os = "emscripten")))] diff --git a/src/libstd/sync/mpsc/oneshot.rs b/src/libstd/sync/mpsc/oneshot.rs index 7389280b853..767e9f96ac8 100644 --- a/src/libstd/sync/mpsc/oneshot.rs +++ b/src/libstd/sync/mpsc/oneshot.rs @@ -113,6 +113,8 @@ impl<T> Packet<T> { // Couldn't send the data, the port hung up first. Return the data // back up the stack. DISCONNECTED => { + self.state.swap(DISCONNECTED, Ordering::SeqCst); + self.upgrade = NothingSent; Err(self.data.take().unwrap()) } |
