Skip to content

Commit

Permalink
spawn <5 threads in RwLock concurrent_read_write test
Browse files Browse the repository at this point in the history
Loom wasn't working otherwise.
  • Loading branch information
KaiJewson committed Dec 25, 2020
1 parent 93b9a87 commit 588b658
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions tokio/src/sync/tests/loom_rwlock.rs
Expand Up @@ -67,19 +67,15 @@ fn concurrent_read_write() {
});
});

let rwclone = rwlock.clone();
let t4 = thread::spawn(move || {
block_on(async {
let guard = rwclone.read_owned().await;
//at this state the value on the lock may either be 0, 5, or 10
assert!(*guard == 0 || *guard == 5 || *guard == 10);
});
});
{
let guard = block_on(rwlock.clone().read_owned());
//at this state the value on the lock may either be 0, 5, or 10
assert!(*guard == 0 || *guard == 5 || *guard == 10);
}

t1.join().expect("thread 1 write should not panic");
t2.join().expect("thread 2 write should not panic");
t3.join().expect("thread 3 read should not panic");
t4.join().expect("thread 4 read should not panic");

let guard = block_on(rwlock.read());
//when all threads have finished the value on the lock should be 10
Expand Down

0 comments on commit 588b658

Please sign in to comment.