Skip to content

Commit

Permalink
simplify test
Browse files Browse the repository at this point in the history
  • Loading branch information
ngoldbaum committed Sep 19, 2024
1 parent 37ffa3a commit 10f5faf
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/types/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,15 @@ mod tests {

#[test]
fn test_pymutex_blocks() {
let mutex = OnceLock::<PyMutex<()>>::new();
let mutex = PyMutex::new(());
let first_thread_locked_once = OnceLock::<bool>::new();
let second_thread_locked_once = OnceLock::<bool>::new();
let finished = OnceLock::<bool>::new();
let (sender, receiver) = sync_channel::<bool>(0);

mutex.get_or_init(|| PyMutex::new(()));

std::thread::scope(|s| {
s.spawn(|| {
let guard = mutex.get().unwrap().lock();
let guard = mutex.lock();
first_thread_locked_once.set(true).unwrap();
while finished.get().is_none() {
if second_thread_locked_once.get().is_some() {
Expand All @@ -141,7 +139,6 @@ mod tests {

s.spawn(|| {
while first_thread_locked_once.get().is_none() {}
let mutex = mutex.get().unwrap();
second_thread_locked_once.set(true).unwrap();
let guard = mutex.lock();
assert!(finished.get().unwrap());
Expand Down

0 comments on commit 10f5faf

Please sign in to comment.