rust/tests/fail/sync/libc_pthread_rwlock_write_write_deadlock.rs

33 lines
735 B
Rust
Raw Normal View History

2020-04-05 13:25:49 -05:00
// ignore-windows: No libc on Windows
#![feature(rustc_private)]
extern crate libc;
2020-04-19 16:22:55 -05:00
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)))
}
2020-04-05 13:25:49 -05:00
fn main() {
unsafe {
2020-04-19 16:22:55 -05:00
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();
2020-04-05 13:25:49 -05:00
}
}