Skip to content

Commit

Permalink
sync: Ensure try_send() wakes up receivers
Browse files Browse the repository at this point in the history
This branch of try_send() just forgot to wake up any receiver waiting for data.

Closes #15761
  • Loading branch information
alexcrichton committed Jul 18, 2014
1 parent e288fc6 commit 31eb00c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/libsync/comm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
})
}
8 changes: 7 additions & 1 deletion src/libsync/comm/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
}
Expand Down

9 comments on commit 31eb00c

@bors
Copy link
Contributor

@bors bors commented on 31eb00c Jul 19, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from kballard
at alexcrichton@31eb00c

@bors
Copy link
Contributor

@bors bors commented on 31eb00c Jul 19, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@bors
Copy link
Contributor

@bors bors commented on 31eb00c Jul 19, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@bors
Copy link
Contributor

@bors bors commented on 31eb00c Jul 20, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from kballard
at alexcrichton@31eb00c

@bors
Copy link
Contributor

@bors bors commented on 31eb00c Jul 20, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@bors
Copy link
Contributor

@bors bors commented on 31eb00c Jul 20, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@bors
Copy link
Contributor

@bors bors commented on 31eb00c Jul 20, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 5e0a597

Please sign in to comment.