MCPcopy Create free account
hub / github.com/CodeSentryAI/lockbud / std_deadlock_wait

Function std_deadlock_wait

toys/condvar-closure/src/main.rs:29–56  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

27}
28
29fn std_deadlock_wait() {
30 use std::sync::{Condvar, Mutex};
31 let mu1 = Arc::new(Mutex::new(1));
32 let mu2 = mu1.clone();
33
34 let pair1 = Arc::new((Mutex::new(false), Condvar::new()));
35 let pair2 = pair1.clone();
36
37 let th1 = thread::spawn(move || {
38 let _i = mu1.lock().unwrap();
39 let (lock, cvar) = &*pair1;
40 let mut started = lock.lock().unwrap();
41 while !*started {
42 started = cvar.wait(started).unwrap();
43 }
44 });
45
46 let th2 = thread::spawn(move || {
47 let _i = mu2.lock().unwrap();
48 let (lock, cvar) = &*pair2;
49 let mut started = lock.lock().unwrap();
50 *started = true;
51 cvar.notify_one();
52 });
53
54 th1.join().unwrap();
55 th2.join().unwrap();
56}
57
58fn std_missing_lock_before_notify() {
59 use std::sync::{Condvar, Mutex};

Callers 1

mainFunction · 0.70

Calls 1

waitMethod · 0.80

Tested by

no test coverage detected