Skip to content

Strange scope issue when use lock (cause deadlock) #60107

Closed
@TheWaWaR

Description

@TheWaWaR

The code:

use std::sync::Mutex;

#[derive(Clone, Debug)]
struct A {}

fn main() {
    let n = Mutex::new(Some(A {}));
    
    if let Some(a) = { let a = n.lock().unwrap(); a.clone() } {
        n.lock();
    }
    
    println!("This is ok");
    
    if let Some(a) = { let a = n.lock(); a.unwrap().clone() } {
        n.lock();
    }

    println!("Never reached !!!!");
}

Output:

    Finished dev [unoptimized + debuginfo] target(s) in 0.56s
     Running `target/debug/playground`
/root/entrypoint.sh: line 8:     7 Killed                  timeout --signal=KILL ${timeout} "$@"
Standard Output
This is ok

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