more idiomatic example

This commit is contained in:
Daniella / Tove 2024-07-14 08:12:39 +00:00
parent a7a57b23f7
commit 630d95cde4
3 changed files with 5 additions and 3 deletions

2
Cargo.lock generated
View file

@ -4,4 +4,4 @@ version = 3
[[package]] [[package]]
name = "microlock" name = "microlock"
version = "0.2.0" version = "0.2.1"

View file

@ -26,7 +26,8 @@ fn main() {
thread::spawn(move || loop { thread::spawn(move || loop {
LOCK.wait_here(); LOCK.wait_here();
println!("{}", queue2.lock().unwrap().pop_front().unwrap()); println!("{}", queue2.lock().unwrap().pop_front().unwrap());
LOCK.lock(); // try_lock because another unlock *could*ve happened since then
LOCK.try_lock();
}); });
let timer = TimedLock::unlocked(); let timer = TimedLock::unlocked();

View file

@ -13,7 +13,8 @@ fn main() {
thread::spawn(move || loop { thread::spawn(move || loop {
LOCK.wait_here(); LOCK.wait_here();
println!("{}", queue2.lock().unwrap().pop_front().unwrap()); println!("{}", queue2.lock().unwrap().pop_front().unwrap());
LOCK.lock(); // try_lock because another unlock *could*ve happened since then
LOCK.try_lock();
}); });
let timer = TimedLock::unlocked(); let timer = TimedLock::unlocked();