Skip to content

Commit 46957f0

Browse files
authored
Auto merge of rust-lang#36893 - apasel422:issue-32114, r=alexcrichton
Restore `DISCONNECTED` state in `oneshot::Packet::send` Closes rust-lang#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.
2 parents 3210fd5 + fb90e4c commit 46957f0

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

Diff for: src/libstd/sync/mpsc/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1940,6 +1940,13 @@ mod tests {
19401940
// wait for the child thread to exit before we exit
19411941
rx2.recv().unwrap();
19421942
}
1943+
1944+
#[test]
1945+
fn issue_32114() {
1946+
let (tx, _) = channel();
1947+
let _ = tx.send(123);
1948+
assert_eq!(tx.send(123), Err(SendError(123)));
1949+
}
19431950
}
19441951

19451952
#[cfg(all(test, not(target_os = "emscripten")))]

Diff for: src/libstd/sync/mpsc/oneshot.rs

+2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ impl<T> Packet<T> {
113113
// Couldn't send the data, the port hung up first. Return the data
114114
// back up the stack.
115115
DISCONNECTED => {
116+
self.state.swap(DISCONNECTED, Ordering::SeqCst);
117+
self.upgrade = NothingSent;
116118
Err(self.data.take().unwrap())
117119
}
118120

0 commit comments

Comments
 (0)