Skip to content

Commit

Permalink
Tidy up rust-lang#1
Browse files Browse the repository at this point in the history
  • Loading branch information
JCTyblaidd committed Dec 14, 2020
1 parent f7dbd02 commit 93e90c5
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 14 deletions.
4 changes: 2 additions & 2 deletions tests/compile-fail/live_lock/live_lock_condvar.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -29,4 +29,4 @@ fn main() {
}
}
}
}
}
2 changes: 1 addition & 1 deletion tests/compile-fail/live_lock/live_lock_contention.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/compile-fail/live_lock/live_lock_deadlock.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/compile-fail/live_lock/live_lock_separate.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
51 changes: 51 additions & 0 deletions tests/compile-fail/live_lock/live_lock_spin_deadlock.rs
Original file line number Diff line number Diff line change
@@ -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();
}
6 changes: 3 additions & 3 deletions tests/compile-fail/live_lock/live_lock_try_mutex.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
}
};
Expand All @@ -26,4 +26,4 @@ fn main() {

j1.join().unwrap();
*s_guard = 1;
}
}
6 changes: 3 additions & 3 deletions tests/compile-fail/live_lock/live_lock_try_rwlock_read.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,12 +17,12 @@ fn main() {
// yield loop for try-lock.
if let Ok(guard) = s1.try_read() {
break guard
}else{
} else {
unsafe { miri_yield_thread(); } //~ERROR livelock
}
};
});

j1.join().unwrap();
*s_guard = 1;
}
}
6 changes: 3 additions & 3 deletions tests/compile-fail/live_lock/live_lock_try_rwlock_write.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
}
};
Expand All @@ -26,4 +26,4 @@ fn main() {

j1.join().unwrap();
*s_guard = 1;
}
}

0 comments on commit 93e90c5

Please sign in to comment.