]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/fail/shims/sync/libc_pthread_rwlock_write_write_deadlock.rs
Add 'src/tools/miri/' from commit '75dd959a3a40eb5b4574f8d2e23aa6efbeb33573'
[rust.git] / src / tools / miri / tests / fail / shims / sync / libc_pthread_rwlock_write_write_deadlock.rs
1 //@ignore-target-windows: No libc on Windows
2
3 use std::cell::UnsafeCell;
4 use std::sync::Arc;
5 use std::thread;
6
7 struct RwLock(UnsafeCell<libc::pthread_rwlock_t>);
8
9 unsafe impl Send for RwLock {}
10 unsafe impl Sync for RwLock {}
11
12 fn new_lock() -> Arc<RwLock> {
13     Arc::new(RwLock(UnsafeCell::new(libc::PTHREAD_RWLOCK_INITIALIZER)))
14 }
15
16 fn main() {
17     unsafe {
18         let lock = new_lock();
19         assert_eq!(libc::pthread_rwlock_wrlock(lock.0.get() as *mut _), 0);
20
21         let lock_copy = lock.clone();
22         thread::spawn(move || {
23             assert_eq!(libc::pthread_rwlock_wrlock(lock_copy.0.get() as *mut _), 0); //~ ERROR: deadlock
24         })
25         .join()
26         .unwrap();
27     }
28 }