From 93e90c5b1c6918bf56c6dc06f433345e04744e56 Mon Sep 17 00:00:00 2001 From: JCTyblaidd Date: Mon, 14 Dec 2020 23:37:20 +0000 Subject: [PATCH] Tidy up #1 --- .../live_lock/live_lock_condvar.rs | 4 +- .../live_lock/live_lock_contention.rs | 2 +- .../live_lock/live_lock_deadlock.rs | 2 +- .../live_lock/live_lock_separate.rs | 2 +- .../live_lock/live_lock_spin_deadlock.rs | 51 +++++++++++++++++++ .../live_lock/live_lock_try_mutex.rs | 6 +-- .../live_lock/live_lock_try_rwlock_read.rs | 6 +-- .../live_lock/live_lock_try_rwlock_write.rs | 6 +-- 8 files changed, 65 insertions(+), 14 deletions(-) create mode 100644 tests/compile-fail/live_lock/live_lock_spin_deadlock.rs diff --git a/tests/compile-fail/live_lock/live_lock_condvar.rs b/tests/compile-fail/live_lock/live_lock_condvar.rs index 1fc39a1f08..501c8289ca 100644 --- a/tests/compile-fail/live_lock/live_lock_condvar.rs +++ b/tests/compile-fail/live_lock/live_lock_condvar.rs @@ -1,5 +1,5 @@ // compile-flags: -Zmiri-disable-isolation -// ignore-windows: No libc on Windows +// ignore-windows: Concurrency on Windows is not supported yet. // FIXME: the implicit mutex unlock & lock counts as forward progress with the current detector, // so this runs forever. Ideally this case should be detected. @@ -29,4 +29,4 @@ fn main() { } } } -} \ No newline at end of file +} diff --git a/tests/compile-fail/live_lock/live_lock_contention.rs b/tests/compile-fail/live_lock/live_lock_contention.rs index 0561ad606f..1c22f3cee1 100644 --- a/tests/compile-fail/live_lock/live_lock_contention.rs +++ b/tests/compile-fail/live_lock/live_lock_contention.rs @@ -1,4 +1,4 @@ -// ignore-windows: No libc on Windows +// ignore-windows: Concurrency on Windows is not supported yet. use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; diff --git a/tests/compile-fail/live_lock/live_lock_deadlock.rs b/tests/compile-fail/live_lock/live_lock_deadlock.rs index 23a86a88a7..87e1feecdc 100644 --- a/tests/compile-fail/live_lock/live_lock_deadlock.rs +++ b/tests/compile-fail/live_lock/live_lock_deadlock.rs @@ -1,4 +1,4 @@ -// ignore-windows: No libc on Windows +// ignore-windows: Concurrency on Windows is not supported yet. use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; diff --git a/tests/compile-fail/live_lock/live_lock_separate.rs b/tests/compile-fail/live_lock/live_lock_separate.rs index af5df2a4c4..8e13d360fc 100644 --- a/tests/compile-fail/live_lock/live_lock_separate.rs +++ b/tests/compile-fail/live_lock/live_lock_separate.rs @@ -1,4 +1,4 @@ -// ignore-windows: No libc on Windows +// ignore-windows: Concurrency on Windows is not supported yet. use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; diff --git a/tests/compile-fail/live_lock/live_lock_spin_deadlock.rs b/tests/compile-fail/live_lock/live_lock_spin_deadlock.rs new file mode 100644 index 0000000000..392e89e3b3 --- /dev/null +++ b/tests/compile-fail/live_lock/live_lock_spin_deadlock.rs @@ -0,0 +1,51 @@ +// ignore-windows: Concurrency on Windows is not supported yet. + +use std::sync::atomic::{AtomicUsize, Ordering}; +use std::sync::Arc; +use std::thread::spawn; + +extern "Rust" { + fn miri_yield_thread(); +} + +struct SpinLock(AtomicUsize); +impl SpinLock { + fn new() -> Self { + Self(AtomicUsize::new(0)) + } + fn lock(&self) { + loop { + if let Ok(_) = self.0.compare_exchange_weak(0, 1, Ordering::Acquire, Ordering::Relaxed) { + break + } else { + unsafe { miri_yield_thread(); } //~ERROR livelock + } + } + } + fn unlock(&self) { + self.0.store(0, Ordering::Release); + } +} + +fn main() { + // forces a deadlock via yield points + let shared = Arc::new((SpinLock::new(),SpinLock::new())); + let s1 = shared.clone(); + let s2 = shared.clone(); + let j1 = spawn(move || { + s1.0.lock(); + std::thread::yield_now(); + s1.1.lock(); + s1.1.unlock(); + s1.0.unlock(); + }); + let j2 = spawn(move || { + s2.1.lock(); + std::thread::yield_now(); + s2.0.lock(); + s2.0.unlock(); + s2.1.unlock(); + }); + j1.join().unwrap(); + j2.join().unwrap(); +} \ No newline at end of file diff --git a/tests/compile-fail/live_lock/live_lock_try_mutex.rs b/tests/compile-fail/live_lock/live_lock_try_mutex.rs index 899f842091..a813441630 100644 --- a/tests/compile-fail/live_lock/live_lock_try_mutex.rs +++ b/tests/compile-fail/live_lock/live_lock_try_mutex.rs @@ -1,4 +1,4 @@ -// ignore-windows: No libc on Windows +// ignore-windows: Concurrency on Windows is not supported yet. use std::sync::{Arc, Mutex}; use std::thread::spawn; @@ -17,7 +17,7 @@ fn main() { // yield loop for try-lock. if let Ok(guard) = s1.try_lock() { break guard - }else{ + } else { unsafe { miri_yield_thread(); } //~ERROR livelock } }; @@ -26,4 +26,4 @@ fn main() { j1.join().unwrap(); *s_guard = 1; -} \ No newline at end of file +} diff --git a/tests/compile-fail/live_lock/live_lock_try_rwlock_read.rs b/tests/compile-fail/live_lock/live_lock_try_rwlock_read.rs index 0ce8360918..431a7859a2 100644 --- a/tests/compile-fail/live_lock/live_lock_try_rwlock_read.rs +++ b/tests/compile-fail/live_lock/live_lock_try_rwlock_read.rs @@ -1,4 +1,4 @@ -// ignore-windows: No libc on Windows +// ignore-windows: Concurrency on Windows is not supported yet. use std::sync::{Arc, RwLock}; use std::thread::spawn; @@ -17,7 +17,7 @@ fn main() { // yield loop for try-lock. if let Ok(guard) = s1.try_read() { break guard - }else{ + } else { unsafe { miri_yield_thread(); } //~ERROR livelock } }; @@ -25,4 +25,4 @@ fn main() { j1.join().unwrap(); *s_guard = 1; -} \ No newline at end of file +} diff --git a/tests/compile-fail/live_lock/live_lock_try_rwlock_write.rs b/tests/compile-fail/live_lock/live_lock_try_rwlock_write.rs index 0fc53b3b8f..f10e12e4d7 100644 --- a/tests/compile-fail/live_lock/live_lock_try_rwlock_write.rs +++ b/tests/compile-fail/live_lock/live_lock_try_rwlock_write.rs @@ -1,4 +1,4 @@ -// ignore-windows: No libc on Windows +// ignore-windows: Concurrency on Windows is not supported yet. use std::sync::{Arc, RwLock}; use std::thread::spawn; @@ -17,7 +17,7 @@ fn main() { // yield loop for try-lock. if let Ok(guard) = s1.try_write() { break guard - }else{ + } else { unsafe { miri_yield_thread(); } //~ERROR livelock } }; @@ -26,4 +26,4 @@ fn main() { j1.join().unwrap(); *s_guard = 1; -} \ No newline at end of file +}