Skip to content

extra::sync has racy functions #7522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mstewartgallus opened this issue Jul 1, 2013 · 2 comments
Closed

extra::sync has racy functions #7522

mstewartgallus opened this issue Jul 1, 2013 · 2 comments

Comments

@mstewartgallus
Copy link
Contributor

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
    }
}
@bblum
Copy link
Contributor

bblum commented Jul 1, 2013

All uses of signal_waitqueue() are protected by a mutex surrounding the waitqueue. You'll note that the only place Waitqueues appear in the data structure hierarchy is in SemInner, which always appears inside of an Exclusive.

The function could probably do with a comment explaining that, though.

@mstewartgallus
Copy link
Contributor Author

Thanks. I feel silly. I'll fix it up when I submit my patches for giving a RAII interface to extra::arc.

flip1995 pushed a commit to flip1995/rust that referenced this issue Aug 12, 2021
Cover `Result` on `map_flatten` lint

Closes rust-lang#7496

changelog: `[map_flatten]` handles `Result` type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants