]>
git.proxmox.com Git - rustc.git/blob - src/test/run-pass/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.
13 use std
::process
::{Command, Stdio}
;
15 use std
::sync
::{Mutex, RwLock}
;
16 use std
::time
::Duration
;
20 let m
= Mutex
::new(0);
21 let _g
= m
.lock().unwrap();
22 let _g2
= m
.lock().unwrap();
26 let m
= Mutex
::new(0);
27 let _g
= m
.lock().unwrap();
28 let _g2
= m
.try_lock().unwrap();
32 let m
= RwLock
::new(0);
33 let _g
= m
.write().unwrap();
34 let _g2
= m
.write().unwrap();
37 fn test_try_rwlock_ww() {
38 let m
= RwLock
::new(0);
39 let _g
= m
.write().unwrap();
40 let _g2
= m
.try_write().unwrap();
44 let m
= RwLock
::new(0);
45 let _g
= m
.read().unwrap();
46 let _g2
= m
.write().unwrap();
49 fn test_try_rwlock_rw() {
50 let m
= RwLock
::new(0);
51 let _g
= m
.read().unwrap();
52 let _g2
= m
.try_write().unwrap();
56 let m
= RwLock
::new(0);
57 let _g
= m
.write().unwrap();
58 let _g2
= m
.read().unwrap();
61 fn test_try_rwlock_wr() {
62 let m
= RwLock
::new(0);
63 let _g
= m
.write().unwrap();
64 let _g2
= m
.try_read().unwrap();
68 let args
: Vec
<String
> = env
::args().collect();
71 "mutex" => test_mutex(),
72 "try_mutex" => test_try_mutex(),
73 "rwlock_ww" => test_rwlock_ww(),
74 "try_rwlock_ww" => test_try_rwlock_ww(),
75 "rwlock_rw" => test_rwlock_rw(),
76 "try_rwlock_rw" => test_try_rwlock_rw(),
77 "rwlock_wr" => test_rwlock_wr(),
78 "try_rwlock_wr" => test_try_rwlock_wr(),
81 // If we reach this point then the test failed
82 println
!("TEST FAILED: {}", args
[1]);
85 v
.push(Command
::new(&args
[0]).arg("mutex").stderr(Stdio
::null()).spawn().unwrap());
86 v
.push(Command
::new(&args
[0]).arg("try_mutex").stderr(Stdio
::null()).spawn().unwrap());
87 v
.push(Command
::new(&args
[0]).arg("rwlock_ww").stderr(Stdio
::null()).spawn().unwrap());
88 v
.push(Command
::new(&args
[0]).arg("try_rwlock_ww").stderr(Stdio
::null()).spawn().unwrap());
89 v
.push(Command
::new(&args
[0]).arg("rwlock_rw").stderr(Stdio
::null()).spawn().unwrap());
90 v
.push(Command
::new(&args
[0]).arg("try_rwlock_rw").stderr(Stdio
::null()).spawn().unwrap());
91 v
.push(Command
::new(&args
[0]).arg("rwlock_wr").stderr(Stdio
::null()).spawn().unwrap());
92 v
.push(Command
::new(&args
[0]).arg("try_rwlock_wr").stderr(Stdio
::null()).spawn().unwrap());
94 thread
::sleep(Duration
::new(1, 0));
96 // Make sure all subprocesses either panicked or were killed because they deadlocked
99 assert
!(!c
.wait().unwrap().success());