schets / multiqueue

A fast mpmc queue with broadcast capabilities
MIT License
201 stars 29 forks source link

MPMC queue deadlocks #17

Open ghost opened 7 years ago

ghost commented 7 years ago

The following code deadlocks on my machine. You might have to run several times to hit the bug.

extern crate crossbeam;
extern crate multiqueue;

fn main() {
    const MESSAGES: usize = 1_000_000;
    const THREADS: usize = 2;

    let (tx, rx) = multiqueue::mpmc_queue(MESSAGES as u64);

    crossbeam::scope(|s| {
        for _ in 0..THREADS {
            let tx = tx.clone();
            s.spawn(move || {
                for _ in 0..MESSAGES / THREADS {
                    while tx.try_send(()).is_err() {}
                }
            });
        }
        for _ in 0..THREADS {
            let rx = rx.clone();
            s.spawn(move || {
                for _ in 0..MESSAGES / THREADS {
                    rx.recv().unwrap();
                }
            });
        }
    });
}
schets commented 6 years ago

thanks, pulling this out of hibernation so will look at it. Fixing some bugs I never got around to and that may reveal the cause of this

jonathanstrong commented 6 years ago

hey - was wondering: did you ever make headway on this? just ran it with the current version and encountered a deadlock. I spent a few minutes trying to discern what was happening but couldn't make heads or tails of it. Even if it can't be fixed immediately, it'd be nice to know what part of the code triggered the condition, if known. Thanks!

schets commented 6 years ago

There is at least one bug with the current implementation, I'm working out a whether this directly competes with my current job before I do any future work though

rivertam commented 5 years ago

I believe this is occurring with Tokio: https://stackoverflow.com/questions/53711246/tokio-with-multiqueue-sometimes-hangs-sometimes-works