diff options
| author | bors <bors@rust-lang.org> | 2014-02-17 14:16:53 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-02-17 14:16:53 -0800 |
| commit | 5736deb90e8f4c15a09c8dec5e1f3467b805fe70 (patch) | |
| tree | 271b953e009e0a4a0cba8e11019eb16b1241b643 /src/libstd | |
| parent | 47c31831a38bc2307234e54a48ad3bf071058ade (diff) | |
| parent | 9c05c1c2366e286275c2320995ed5066bff08dd7 (diff) | |
| download | rust-5736deb90e8f4c15a09c8dec5e1f3467b805fe70.tar.gz rust-5736deb90e8f4c15a09c8dec5e1f3467b805fe70.zip | |
auto merge of #12352 : alexcrichton/rust/fix-master, r=brson
This deadlock was caused when the channel was closed at just the right time, so the extra `self.cnt.fetch_add` actually should have preserved the DISCONNECTED state of the channel. by modifying this the channel entered a state such that the port would never succeed in dropping. This also moves the increment of self.steals until after the MAX_STEALS block. The reason for this is that in 'fn recv()' the steals variable is decremented immediately after the try_recv(), which could in theory set steals to -1 if it was previously set to 0 in try_recv(). Closes #12340
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/comm/shared.rs | 4 | ||||
| -rw-r--r-- | src/libstd/comm/stream.rs | 4 |
2 files changed, 4 insertions, 4 deletions
diff --git a/src/libstd/comm/shared.rs b/src/libstd/comm/shared.rs index 832cdca12f0..0884c46ee84 100644 --- a/src/libstd/comm/shared.rs +++ b/src/libstd/comm/shared.rs @@ -305,7 +305,6 @@ impl<T: Send> Packet<T> { // See the discussion in the stream implementation for why we we // might decrement steals. Some(data) => { - self.steals += 1; if self.steals > MAX_STEALS { match self.cnt.swap(0, atomics::SeqCst) { DISCONNECTED => { @@ -314,11 +313,12 @@ impl<T: Send> Packet<T> { n => { let m = cmp::min(n, self.steals); self.steals -= m; - self.cnt.fetch_add(n - m, atomics::SeqCst); + self.bump(n - m); } } assert!(self.steals >= 0); } + self.steals += 1; Ok(data) } diff --git a/src/libstd/comm/stream.rs b/src/libstd/comm/stream.rs index f1988dbbeed..0bacf1e1d28 100644 --- a/src/libstd/comm/stream.rs +++ b/src/libstd/comm/stream.rs @@ -213,7 +213,6 @@ impl<T: Send> Packet<T> { // down as much as possible (without going negative), and then // adding back in whatever we couldn't factor into steals. Some(data) => { - self.steals += 1; if self.steals > MAX_STEALS { match self.cnt.swap(0, atomics::SeqCst) { DISCONNECTED => { @@ -222,11 +221,12 @@ impl<T: Send> Packet<T> { n => { let m = cmp::min(n, self.steals); self.steals -= m; - self.cnt.fetch_add(n - m, atomics::SeqCst); + self.bump(n - m); } } assert!(self.steals >= 0); } + self.steals += 1; match data { Data(t) => Ok(t), GoUp(up) => Err(Upgraded(up)), |
