-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #33861 - Amanieu:lock_elision_fix, r=alexcrichton
Make sure Mutex and RwLock can't be re-locked on the same thread Fixes #33770 r? @alexcrichton
- Loading branch information
Showing
7 changed files
with
214 additions
and
11 deletions.
There are no files selected for viewing
Submodule liblibc
updated
24 files
+1 −0 | libc-test/build.rs | |
+12 −0 | src/unix/bsd/apple/mod.rs | |
+11 −0 | src/unix/bsd/freebsdlike/mod.rs | |
+5 −0 | src/unix/bsd/openbsdlike/bitrig.rs | |
+4 −0 | src/unix/bsd/openbsdlike/mod.rs | |
+3 −0 | src/unix/bsd/openbsdlike/netbsd.rs | |
+5 −0 | src/unix/bsd/openbsdlike/openbsd.rs | |
+10 −0 | src/unix/mod.rs | |
+19 −0 | src/unix/notbsd/android/b32.rs | |
+19 −0 | src/unix/notbsd/android/b64.rs | |
+17 −0 | src/unix/notbsd/android/mod.rs | |
+18 −0 | src/unix/notbsd/linux/mips.rs | |
+3 −0 | src/unix/notbsd/linux/mod.rs | |
+31 −30 | src/unix/notbsd/linux/musl/b32/arm.rs | |
+31 −30 | src/unix/notbsd/linux/musl/b32/asmjs.rs | |
+31 −30 | src/unix/notbsd/linux/musl/b32/mips.rs | |
+31 −30 | src/unix/notbsd/linux/musl/b32/x86.rs | |
+31 −30 | src/unix/notbsd/linux/musl/b64/mod.rs | |
+20 −1 | src/unix/notbsd/linux/musl/mod.rs | |
+17 −0 | src/unix/notbsd/linux/other/b32/mod.rs | |
+17 −0 | src/unix/notbsd/linux/other/b64/mod.rs | |
+11 −0 | src/unix/notbsd/linux/other/mod.rs | |
+4 −0 | src/unix/notbsd/mod.rs | |
+7 −0 | src/unix/solaris/mod.rs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
use std::process::{Command, Stdio}; | ||
use std::env; | ||
use std::sync::{Mutex, RwLock}; | ||
use std::time::Duration; | ||
use std::thread; | ||
|
||
fn test_mutex() { | ||
let m = Mutex::new(0); | ||
let _g = m.lock().unwrap(); | ||
let _g2 = m.lock().unwrap(); | ||
} | ||
|
||
fn test_try_mutex() { | ||
let m = Mutex::new(0); | ||
let _g = m.lock().unwrap(); | ||
let _g2 = m.try_lock().unwrap(); | ||
} | ||
|
||
fn test_rwlock_ww() { | ||
let m = RwLock::new(0); | ||
let _g = m.write().unwrap(); | ||
let _g2 = m.write().unwrap(); | ||
} | ||
|
||
fn test_try_rwlock_ww() { | ||
let m = RwLock::new(0); | ||
let _g = m.write().unwrap(); | ||
let _g2 = m.try_write().unwrap(); | ||
} | ||
|
||
fn test_rwlock_rw() { | ||
let m = RwLock::new(0); | ||
let _g = m.read().unwrap(); | ||
let _g2 = m.write().unwrap(); | ||
} | ||
|
||
fn test_try_rwlock_rw() { | ||
let m = RwLock::new(0); | ||
let _g = m.read().unwrap(); | ||
let _g2 = m.try_write().unwrap(); | ||
} | ||
|
||
fn test_rwlock_wr() { | ||
let m = RwLock::new(0); | ||
let _g = m.write().unwrap(); | ||
let _g2 = m.read().unwrap(); | ||
} | ||
|
||
fn test_try_rwlock_wr() { | ||
let m = RwLock::new(0); | ||
let _g = m.write().unwrap(); | ||
let _g2 = m.try_read().unwrap(); | ||
} | ||
|
||
fn main() { | ||
let args: Vec<String> = env::args().collect(); | ||
if args.len() > 1 { | ||
match &*args[1] { | ||
"mutex" => test_mutex(), | ||
"try_mutex" => test_try_mutex(), | ||
"rwlock_ww" => test_rwlock_ww(), | ||
"try_rwlock_ww" => test_try_rwlock_ww(), | ||
"rwlock_rw" => test_rwlock_rw(), | ||
"try_rwlock_rw" => test_try_rwlock_rw(), | ||
"rwlock_wr" => test_rwlock_wr(), | ||
"try_rwlock_wr" => test_try_rwlock_wr(), | ||
_ => unreachable!(), | ||
} | ||
// If we reach this point then the test failed | ||
println!("TEST FAILED: {}", args[1]); | ||
} else { | ||
let mut v = vec![]; | ||
v.push(Command::new(&args[0]).arg("mutex").stderr(Stdio::null()).spawn().unwrap()); | ||
v.push(Command::new(&args[0]).arg("try_mutex").stderr(Stdio::null()).spawn().unwrap()); | ||
v.push(Command::new(&args[0]).arg("rwlock_ww").stderr(Stdio::null()).spawn().unwrap()); | ||
v.push(Command::new(&args[0]).arg("try_rwlock_ww").stderr(Stdio::null()).spawn().unwrap()); | ||
v.push(Command::new(&args[0]).arg("rwlock_rw").stderr(Stdio::null()).spawn().unwrap()); | ||
v.push(Command::new(&args[0]).arg("try_rwlock_rw").stderr(Stdio::null()).spawn().unwrap()); | ||
v.push(Command::new(&args[0]).arg("rwlock_wr").stderr(Stdio::null()).spawn().unwrap()); | ||
v.push(Command::new(&args[0]).arg("try_rwlock_wr").stderr(Stdio::null()).spawn().unwrap()); | ||
|
||
thread::sleep(Duration::new(1, 0)); | ||
|
||
// Make sure all subprocesses either panicked or were killed because they deadlocked | ||
for mut c in v { | ||
c.kill().ok(); | ||
assert!(!c.wait().unwrap().success()); | ||
} | ||
} | ||
} |