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

Function std_correct

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

Source from the content-addressed store, hash-verified

2use std::thread;
3
4fn std_correct() {
5 use std::sync::{Condvar, Mutex};
6
7 let pair1 = Arc::new((Mutex::new(false), Condvar::new()));
8 let pair2 = pair1.clone();
9
10 let th1 = thread::spawn(move || {
11 let (lock, cvar) = &*pair1;
12 let mut started = lock.lock().unwrap();
13 while !*started {
14 started = cvar.wait(started).unwrap();
15 }
16 });
17
18 let th2 = thread::spawn(move || {
19 let (lock, cvar) = &*pair2;
20 let mut started = lock.lock().unwrap();
21 *started = true;
22 cvar.notify_one();
23 });
24
25 th1.join().unwrap();
26 th2.join().unwrap();
27}
28
29fn std_deadlock_wait() {
30 use std::sync::{Condvar, Mutex};

Callers 1

mainFunction · 0.70

Calls 1

waitMethod · 0.80

Tested by

no test coverage detected