Skip to content

Detecting deadlock with single qutex/qrwlock #1

@yjh0502

Description

@yjh0502

Here's example code which causes deadlock without unsafe code.

extern crate futures;
extern crate qutex;

use qutex::*;
use futures::prelude::*;

fn main() {
    let lock = QrwLock::from(0i32);

    let f = lock.clone().write().and_then(move |mut guard_w| {
        eprintln!("write lock acquired");
        lock.read().and_then(move |guard_r| {
            eprintln!("read lock acquired");

            let r0 = *guard_r;
            *guard_w += 1;
            let r1 = *guard_r;
            assert_eq!(r0, r1);
            Ok(())
        })
    });

    assert_eq!(Ok(()), f.wait());
}

Is there any way to detect the deadlock? It would be nice for FutureGuard to return Deadlocked error (just like Canceled error) if there's any prior FutureGuard which belongs to current task. In that case, above example will return Error(Deadlocked) on f.wait() instead of hanging on deadlock.

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