Skip to content

Commit 80459bb

Browse files
author
Vytautas Astrauskas
committed
Improve concurrency tests.
1 parent 94cbe88 commit 80459bb

16 files changed

+87
-79
lines changed

tests/compile-fail/concurrency/dangling_tls_lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// ignore-windows
1+
// ignore-windows: Concurrency on Windows is not supported yet.
22

33
#![feature(thread_local_internals)]
44

tests/compile-fail/concurrency/libc_pthread_rwlock_write_read_deadlock.rs

Lines changed: 0 additions & 32 deletions
This file was deleted.

tests/compile-fail/concurrency/libc_pthread_rwlock_write_write_deadlock.rs

Lines changed: 0 additions & 32 deletions
This file was deleted.

tests/compile-fail/thread-spawn.rs renamed to tests/compile-fail/concurrency/thread-spawn.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
// ignore-linux
2-
// ignore-macos
1+
// ignore-linux: Only Windows is not supported.
2+
// ignore-macos: Only Windows is not supported.
3+
34
use std::thread;
45

56
// error-pattern: Miri does not support threading

tests/compile-fail/sync/libc_pthread_rwlock_write_read_deadlock.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,29 @@
44

55
extern crate libc;
66

7+
use std::cell::UnsafeCell;
8+
use std::sync::Arc;
9+
use std::thread;
10+
11+
struct RwLock(UnsafeCell<libc::pthread_rwlock_t>);
12+
13+
unsafe impl Send for RwLock {}
14+
unsafe impl Sync for RwLock {}
15+
16+
fn new_lock() -> Arc<RwLock> {
17+
Arc::new(RwLock(UnsafeCell::new(libc::PTHREAD_RWLOCK_INITIALIZER)))
18+
}
19+
720
fn main() {
8-
let rw = std::cell::UnsafeCell::new(libc::PTHREAD_RWLOCK_INITIALIZER);
921
unsafe {
10-
assert_eq!(libc::pthread_rwlock_wrlock(rw.get()), 0);
11-
libc::pthread_rwlock_rdlock(rw.get()); //~ ERROR: deadlock
22+
let lock = new_lock();
23+
assert_eq!(libc::pthread_rwlock_rdlock(lock.0.get() as *mut _), 0);
24+
25+
let lock_copy = lock.clone();
26+
thread::spawn(move || {
27+
assert_eq!(libc::pthread_rwlock_wrlock(lock_copy.0.get() as *mut _), 0); //~ ERROR: deadlock
28+
})
29+
.join()
30+
.unwrap();
1231
}
1332
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// ignore-windows: No libc on Windows
2+
3+
#![feature(rustc_private)]
4+
5+
extern crate libc;
6+
7+
fn main() {
8+
let rw = std::cell::UnsafeCell::new(libc::PTHREAD_RWLOCK_INITIALIZER);
9+
unsafe {
10+
assert_eq!(libc::pthread_rwlock_wrlock(rw.get()), 0);
11+
libc::pthread_rwlock_rdlock(rw.get()); //~ ERROR: deadlock
12+
}
13+
}

tests/compile-fail/sync/libc_pthread_rwlock_write_write_deadlock.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,29 @@
44

55
extern crate libc;
66

7+
use std::cell::UnsafeCell;
8+
use std::sync::Arc;
9+
use std::thread;
10+
11+
struct RwLock(UnsafeCell<libc::pthread_rwlock_t>);
12+
13+
unsafe impl Send for RwLock {}
14+
unsafe impl Sync for RwLock {}
15+
16+
fn new_lock() -> Arc<RwLock> {
17+
Arc::new(RwLock(UnsafeCell::new(libc::PTHREAD_RWLOCK_INITIALIZER)))
18+
}
19+
720
fn main() {
8-
let rw = std::cell::UnsafeCell::new(libc::PTHREAD_RWLOCK_INITIALIZER);
921
unsafe {
10-
assert_eq!(libc::pthread_rwlock_wrlock(rw.get()), 0);
11-
libc::pthread_rwlock_wrlock(rw.get()); //~ ERROR: deadlock
22+
let lock = new_lock();
23+
assert_eq!(libc::pthread_rwlock_wrlock(lock.0.get() as *mut _), 0);
24+
25+
let lock_copy = lock.clone();
26+
thread::spawn(move || {
27+
assert_eq!(libc::pthread_rwlock_wrlock(lock_copy.0.get() as *mut _), 0); //~ ERROR: deadlock
28+
})
29+
.join()
30+
.unwrap();
1231
}
1332
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// ignore-windows: No libc on Windows
2+
3+
#![feature(rustc_private)]
4+
5+
extern crate libc;
6+
7+
fn main() {
8+
let rw = std::cell::UnsafeCell::new(libc::PTHREAD_RWLOCK_INITIALIZER);
9+
unsafe {
10+
assert_eq!(libc::pthread_rwlock_wrlock(rw.get()), 0);
11+
libc::pthread_rwlock_wrlock(rw.get()); //~ ERROR: deadlock
12+
}
13+
}

0 commit comments

Comments
 (0)