Skip to content

loom reports deadlock for Mutex::try_lock #376

@mox692

Description

@mox692

I expected this program not to cause a deadlock:

use loom::sync::{Arc, Mutex};
use loom::thread;

#[test]
fn try_lock() {
    loom::model(|| {
        let lock1 = Arc::new(Mutex::new(0));
        let lock2 = lock1.clone();

        let jh = thread::spawn(move || {
            let _ = lock1.try_lock();
        });

        let guard = lock2.try_lock();

        jh.join().unwrap();

        drop(guard)
    })
}

But actually loom reports a deadlock:

thread 'try_lock' panicked at src/rt/execution.rs:215:13:
deadlock; threads = [(Id(0), Blocked(Location(Some(Location { file: "tests/mutex.rs", line: 16, col: 12 })))), (Id(1), Blocked(Location(Some(Location { file: "tests/mutex.rs", line: 11, col: 27 }))))]
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

coroutine in thread 'try_lock' has overflowed its stack

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions