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

Function std_missing_lock_before_notify

toys/condvar-struct/src/main.rs:94–133  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

92}
93
94fn std_missing_lock_before_notify() {
95 use std::sync::{Condvar, Mutex};
96
97 struct CondPair {
98 lock: Mutex<bool>,
99 cvar: Condvar,
100 }
101
102 impl CondPair {
103 fn new() -> Self {
104 Self {
105 lock: Mutex::new(false),
106 cvar: Condvar::new(),
107 }
108 }
109 fn wait(&self) {
110 let mut started = self.lock.lock().unwrap();
111 println!("start waiting!");
112 while !*started {
113 started = self.cvar.wait(started).unwrap();
114 }
115 println!("end waiting");
116 }
117 fn notify(&self) {
118 println!("start notifying!");
119 self.cvar.notify_one();
120 println!("end notifying!");
121 }
122 }
123
124 let condvar1 = Arc::new(CondPair::new());
125 let condvar2 = condvar1.clone();
126
127 let th1 = thread::spawn(move || {
128 condvar1.wait();
129 });
130
131 condvar2.notify();
132 th1.join().unwrap();
133}
134
135fn parking_lot_correct() {
136 use parking_lot::{Condvar, Mutex};

Callers 1

mainFunction · 0.70

Calls 2

waitMethod · 0.80
notifyMethod · 0.80

Tested by

no test coverage detected