Consider the following function in extra::sync. There is a race condition where after the peek another thread can recv from the head port. This race condition looks like it would cause an accident an extremely small number of times because the peek, and the recv are so close together but when the action does occur it will cause the really bad, and unexpected (to the user of Waitqueue) effect of the signal method to block on head!
fn signal_waitqueue(q: &Waitqueue) -> bool {
// The peek is mandatory to make sure recv doesn't block.
if q.head.peek() {
// Pop and send a wakeup signal. If the waiter was killed, its port
// will have closed. Keep trying until we get a live task.
if comm::try_send_one(q.head.recv(), ()) {
true
} else {
signal_waitqueue(q)
}
} else {
false
}
}
Consider the following function in extra::sync. There is a race condition where after the peek another thread can
recvfrom theheadport. This race condition looks like it would cause an accident an extremely small number of times because thepeek, and therecvare so close together but when the action does occur it will cause the really bad, and unexpected (to the user ofWaitqueue) effect of thesignalmethod to block onhead!