tokio-rs / loom

Concurrency permutation testing tool for Rust.
MIT License
2.09k stars 110 forks source link

Loom does not register that dropping last `sender` of an `mpsc` unblocks a thread waiting on `.recv()` #213

Open MarkDDR opened 3 years ago

MarkDDR commented 3 years ago

When the following code is run, loom claims it deadlocks. This should not happen since the other thread should become unblocked and exit once the last sender gets dropped in drop(sender)

Example repo with the same code

use loom::{sync::mpsc, thread};

fn main() {
    loom::model(|| {
        deadlock_example();
    })
}

fn deadlock_example() {
    let (sender, receiver) = mpsc::channel();

    let handle = thread::spawn(move || {
        while let Ok(i) = receiver.recv() {
            println!("Got {}", i);
        }
    });

    sender.send(0_i32).expect("thread died");

    drop(sender);

    handle.join().expect("thread panicked");
}

This was tested to occur with both loom = "0.4.1" and the current master branch of loom at time of writing

toddlipcon commented 3 months ago

This still seems to be the case. I suppose no one is working on this?