2 // ignore-emscripten no processes
3 // ignore-sgx no processes
5 use std::process::{Command, Stdio};
7 use std::sync::{Mutex, RwLock};
8 use std::time::Duration;
12 let m = Mutex::new(0);
13 let _g = m.lock().unwrap();
14 let _g2 = m.lock().unwrap();
18 let m = Mutex::new(0);
19 let _g = m.lock().unwrap();
20 let _g2 = m.try_lock().unwrap();
24 let m = RwLock::new(0);
25 let _g = m.write().unwrap();
26 let _g2 = m.write().unwrap();
29 fn test_try_rwlock_ww() {
30 let m = RwLock::new(0);
31 let _g = m.write().unwrap();
32 let _g2 = m.try_write().unwrap();
36 let m = RwLock::new(0);
37 let _g = m.read().unwrap();
38 let _g2 = m.write().unwrap();
41 fn test_try_rwlock_rw() {
42 let m = RwLock::new(0);
43 let _g = m.read().unwrap();
44 let _g2 = m.try_write().unwrap();
48 let m = RwLock::new(0);
49 let _g = m.write().unwrap();
50 let _g2 = m.read().unwrap();
53 fn test_try_rwlock_wr() {
54 let m = RwLock::new(0);
55 let _g = m.write().unwrap();
56 let _g2 = m.try_read().unwrap();
60 let args: Vec<String> = env::args().collect();
63 "mutex" => test_mutex(),
64 "try_mutex" => test_try_mutex(),
65 "rwlock_ww" => test_rwlock_ww(),
66 "try_rwlock_ww" => test_try_rwlock_ww(),
67 "rwlock_rw" => test_rwlock_rw(),
68 "try_rwlock_rw" => test_try_rwlock_rw(),
69 "rwlock_wr" => test_rwlock_wr(),
70 "try_rwlock_wr" => test_try_rwlock_wr(),
73 // If we reach this point then the test failed
74 println!("TEST FAILED: {}", args[1]);
77 v.push(Command::new(&args[0]).arg("mutex").stderr(Stdio::null()).spawn().unwrap());
78 v.push(Command::new(&args[0]).arg("try_mutex").stderr(Stdio::null()).spawn().unwrap());
79 v.push(Command::new(&args[0]).arg("rwlock_ww").stderr(Stdio::null()).spawn().unwrap());
80 v.push(Command::new(&args[0]).arg("try_rwlock_ww").stderr(Stdio::null()).spawn().unwrap());
81 v.push(Command::new(&args[0]).arg("rwlock_rw").stderr(Stdio::null()).spawn().unwrap());
82 v.push(Command::new(&args[0]).arg("try_rwlock_rw").stderr(Stdio::null()).spawn().unwrap());
83 v.push(Command::new(&args[0]).arg("rwlock_wr").stderr(Stdio::null()).spawn().unwrap());
84 v.push(Command::new(&args[0]).arg("try_rwlock_wr").stderr(Stdio::null()).spawn().unwrap());
86 thread::sleep(Duration::new(1, 0));
88 // Make sure all subprocesses either panicked or were killed because they deadlocked
91 assert!(!c.wait().unwrap().success());