Improve concurrency tests.

This commit is contained in:
Vytautas Astrauskas 2020-04-19 14:22:55 -07:00
parent 94cbe88e80
commit 80459bbf77
16 changed files with 87 additions and 79 deletions

@ -1,4 +1,4 @@
// ignore-windows
// ignore-windows: Concurrency on Windows is not supported yet.
#![feature(thread_local_internals)]

@ -1,32 +0,0 @@
// ignore-windows: No libc on Windows
#![feature(rustc_private)]
extern crate libc;
use std::cell::UnsafeCell;
use std::sync::Arc;
use std::thread;
struct RwLock(UnsafeCell<libc::pthread_rwlock_t>);
unsafe impl Send for RwLock {}
unsafe impl Sync for RwLock {}
fn new_lock() -> Arc<RwLock> {
Arc::new(RwLock(UnsafeCell::new(libc::PTHREAD_RWLOCK_INITIALIZER)))
}
fn main() {
unsafe {
let lock = new_lock();
assert_eq!(libc::pthread_rwlock_rdlock(lock.0.get() as *mut _), 0);
let lock_copy = lock.clone();
thread::spawn(move || {
assert_eq!(libc::pthread_rwlock_wrlock(lock_copy.0.get() as *mut _), 0); //~ ERROR: deadlock
})
.join()
.unwrap();
}
}

@ -1,32 +0,0 @@
// ignore-windows: No libc on Windows
#![feature(rustc_private)]
extern crate libc;
use std::cell::UnsafeCell;
use std::sync::Arc;
use std::thread;
struct RwLock(UnsafeCell<libc::pthread_rwlock_t>);
unsafe impl Send for RwLock {}
unsafe impl Sync for RwLock {}
fn new_lock() -> Arc<RwLock> {
Arc::new(RwLock(UnsafeCell::new(libc::PTHREAD_RWLOCK_INITIALIZER)))
}
fn main() {
unsafe {
let lock = new_lock();
assert_eq!(libc::pthread_rwlock_wrlock(lock.0.get() as *mut _), 0);
let lock_copy = lock.clone();
thread::spawn(move || {
assert_eq!(libc::pthread_rwlock_wrlock(lock_copy.0.get() as *mut _), 0); //~ ERROR: deadlock
})
.join()
.unwrap();
}
}

@ -1,5 +1,6 @@
// ignore-linux
// ignore-macos
// ignore-linux: Only Windows is not supported.
// ignore-macos: Only Windows is not supported.
use std::thread;
// error-pattern: Miri does not support threading

@ -4,10 +4,29 @@
extern crate libc;
use std::cell::UnsafeCell;
use std::sync::Arc;
use std::thread;
struct RwLock(UnsafeCell<libc::pthread_rwlock_t>);
unsafe impl Send for RwLock {}
unsafe impl Sync for RwLock {}
fn new_lock() -> Arc<RwLock> {
Arc::new(RwLock(UnsafeCell::new(libc::PTHREAD_RWLOCK_INITIALIZER)))
}
fn main() {
let rw = std::cell::UnsafeCell::new(libc::PTHREAD_RWLOCK_INITIALIZER);
unsafe {
assert_eq!(libc::pthread_rwlock_wrlock(rw.get()), 0);
libc::pthread_rwlock_rdlock(rw.get()); //~ ERROR: deadlock
let lock = new_lock();
assert_eq!(libc::pthread_rwlock_rdlock(lock.0.get() as *mut _), 0);
let lock_copy = lock.clone();
thread::spawn(move || {
assert_eq!(libc::pthread_rwlock_wrlock(lock_copy.0.get() as *mut _), 0); //~ ERROR: deadlock
})
.join()
.unwrap();
}
}

@ -0,0 +1,13 @@
// ignore-windows: No libc on Windows
#![feature(rustc_private)]
extern crate libc;
fn main() {
let rw = std::cell::UnsafeCell::new(libc::PTHREAD_RWLOCK_INITIALIZER);
unsafe {
assert_eq!(libc::pthread_rwlock_wrlock(rw.get()), 0);
libc::pthread_rwlock_rdlock(rw.get()); //~ ERROR: deadlock
}
}

@ -4,10 +4,29 @@
extern crate libc;
use std::cell::UnsafeCell;
use std::sync::Arc;
use std::thread;
struct RwLock(UnsafeCell<libc::pthread_rwlock_t>);
unsafe impl Send for RwLock {}
unsafe impl Sync for RwLock {}
fn new_lock() -> Arc<RwLock> {
Arc::new(RwLock(UnsafeCell::new(libc::PTHREAD_RWLOCK_INITIALIZER)))
}
fn main() {
let rw = std::cell::UnsafeCell::new(libc::PTHREAD_RWLOCK_INITIALIZER);
unsafe {
assert_eq!(libc::pthread_rwlock_wrlock(rw.get()), 0);
libc::pthread_rwlock_wrlock(rw.get()); //~ ERROR: deadlock
let lock = new_lock();
assert_eq!(libc::pthread_rwlock_wrlock(lock.0.get() as *mut _), 0);
let lock_copy = lock.clone();
thread::spawn(move || {
assert_eq!(libc::pthread_rwlock_wrlock(lock_copy.0.get() as *mut _), 0); //~ ERROR: deadlock
})
.join()
.unwrap();
}
}

@ -0,0 +1,13 @@
// ignore-windows: No libc on Windows
#![feature(rustc_private)]
extern crate libc;
fn main() {
let rw = std::cell::UnsafeCell::new(libc::PTHREAD_RWLOCK_INITIALIZER);
unsafe {
assert_eq!(libc::pthread_rwlock_wrlock(rw.get()), 0);
libc::pthread_rwlock_wrlock(rw.get()); //~ ERROR: deadlock
}
}

@ -1,4 +1,4 @@
// ignore-windows
// ignore-windows: Concurrency on Windows is not supported yet.
use std::sync::{Arc, Mutex, RwLock};
use std::thread;
@ -11,6 +11,7 @@ fn check_mutex() {
let data = Arc::clone(&data);
let thread = thread::spawn(move || {
let mut data = data.lock().unwrap();
thread::yield_now();
*data += 1;
});
threads.push(thread);
@ -34,6 +35,7 @@ fn check_rwlock_write() {
let data = Arc::clone(&data);
let thread = thread::spawn(move || {
let mut data = data.write().unwrap();
thread::yield_now();
*data += 1;
});
threads.push(thread);

@ -1,2 +1,2 @@
warning: The thread support is experimental. For example, Miri does not detect data races yet.
warning: thread support is experimental. For example, Miri does not detect data races yet.

@ -1,4 +1,4 @@
// ignore-windows
// ignore-windows: Concurrency on Windows is not supported yet.
use std::thread;

@ -1,2 +1,2 @@
warning: The thread support is experimental. For example, Miri does not detect data races yet.
warning: thread support is experimental. For example, Miri does not detect data races yet.

@ -1,4 +1,9 @@
// ignore-windows
// ignore-windows: Concurrency on Windows is not supported yet.
//! The main purpose of this test is to check that if we take a pointer to
//! thread's `t1` thread-local `A` and send it to another thread `t2`,
//! dereferencing the pointer on `t2` resolves to `t1`'s thread-local. In this
//! test, we also check that thread-locals act as per-thread statics.
#![feature(thread_local)]

@ -1,2 +1,2 @@
warning: The thread support is experimental. For example, Miri does not detect data races yet.
warning: thread support is experimental. For example, Miri does not detect data races yet.