Skip to content
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

Deadlock with select-send and select-recv #20

Closed
ghost opened this issue Aug 15, 2017 · 2 comments
Closed

Deadlock with select-send and select-recv #20

ghost opened this issue Aug 15, 2017 · 2 comments

Comments

@ghost
Copy link

ghost commented Aug 15, 2017

Code is worth more than a thousand words. :)

#[macro_use]
extern crate chan;
extern crate crossbeam;

fn main() {
    let (tx, rx) = chan::sync(0);

    // Good.
    crossbeam::scope(|s| {
        let (tx, rx) = (tx.clone(), rx.clone());
        s.spawn(move || tx.send(()));
        s.spawn(move || chan_select! { rx.recv() => {} });
    });

    // Good.
    crossbeam::scope(|s| {
        let (tx, rx) = (tx.clone(), rx.clone());
        s.spawn(move || chan_select! { tx.send(()) => {} });
        s.spawn(move || rx.recv());
    });

    // Deadlock.
    crossbeam::scope(|s| {
        let (tx, rx) = (tx.clone(), rx.clone());
        s.spawn(move || chan_select! { tx.send(()) => {} });
        s.spawn(move || chan_select! { rx.recv() => {} });
    });
}
@BurntSushi
Copy link
Owner

Interesting. Does this happen without using crossbeam? i.e., Does there exist a smaller example?

@ghost
Copy link
Author

ghost commented Aug 15, 2017

Yes. Here's the smallest example I've got:

#[macro_use]
extern crate chan;

use std::thread;

fn main() {
    let (tx, rx) = chan::sync(0);
    thread::spawn(move || chan_select! { tx.send(()) => {} });
    chan_select! { rx.recv() => {} }
}

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

1 participant