]>
git.proxmox.com Git - rustc.git/blob - src/test/run-pass/issues/issue-33770.rs
1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
12 // ignore-cloudabi no processes
13 // ignore-emscripten no processes
15 use std
::process
::{Command, Stdio}
;
17 use std
::sync
::{Mutex, RwLock}
;
18 use std
::time
::Duration
;
22 let m
= Mutex
::new(0);
23 let _g
= m
.lock().unwrap();
24 let _g2
= m
.lock().unwrap();
28 let m
= Mutex
::new(0);
29 let _g
= m
.lock().unwrap();
30 let _g2
= m
.try_lock().unwrap();
34 let m
= RwLock
::new(0);
35 let _g
= m
.write().unwrap();
36 let _g2
= m
.write().unwrap();
39 fn test_try_rwlock_ww() {
40 let m
= RwLock
::new(0);
41 let _g
= m
.write().unwrap();
42 let _g2
= m
.try_write().unwrap();
46 let m
= RwLock
::new(0);
47 let _g
= m
.read().unwrap();
48 let _g2
= m
.write().unwrap();
51 fn test_try_rwlock_rw() {
52 let m
= RwLock
::new(0);
53 let _g
= m
.read().unwrap();
54 let _g2
= m
.try_write().unwrap();
58 let m
= RwLock
::new(0);
59 let _g
= m
.write().unwrap();
60 let _g2
= m
.read().unwrap();
63 fn test_try_rwlock_wr() {
64 let m
= RwLock
::new(0);
65 let _g
= m
.write().unwrap();
66 let _g2
= m
.try_read().unwrap();
70 let args
: Vec
<String
> = env
::args().collect();
73 "mutex" => test_mutex(),
74 "try_mutex" => test_try_mutex(),
75 "rwlock_ww" => test_rwlock_ww(),
76 "try_rwlock_ww" => test_try_rwlock_ww(),
77 "rwlock_rw" => test_rwlock_rw(),
78 "try_rwlock_rw" => test_try_rwlock_rw(),
79 "rwlock_wr" => test_rwlock_wr(),
80 "try_rwlock_wr" => test_try_rwlock_wr(),
83 // If we reach this point then the test failed
84 println
!("TEST FAILED: {}", args
[1]);
87 v
.push(Command
::new(&args
[0]).arg("mutex").stderr(Stdio
::null()).spawn().unwrap());
88 v
.push(Command
::new(&args
[0]).arg("try_mutex").stderr(Stdio
::null()).spawn().unwrap());
89 v
.push(Command
::new(&args
[0]).arg("rwlock_ww").stderr(Stdio
::null()).spawn().unwrap());
90 v
.push(Command
::new(&args
[0]).arg("try_rwlock_ww").stderr(Stdio
::null()).spawn().unwrap());
91 v
.push(Command
::new(&args
[0]).arg("rwlock_rw").stderr(Stdio
::null()).spawn().unwrap());
92 v
.push(Command
::new(&args
[0]).arg("try_rwlock_rw").stderr(Stdio
::null()).spawn().unwrap());
93 v
.push(Command
::new(&args
[0]).arg("rwlock_wr").stderr(Stdio
::null()).spawn().unwrap());
94 v
.push(Command
::new(&args
[0]).arg("try_rwlock_wr").stderr(Stdio
::null()).spawn().unwrap());
96 thread
::sleep(Duration
::new(1, 0));
98 // Make sure all subprocesses either panicked or were killed because they deadlocked
101 assert
!(!c
.wait().unwrap().success());