Skip to content

Commit 0d6c4c5

Browse files
committed
Adds mutex-leak-move-deadlock for panic situation
1 parent af02bb7 commit 0d6c4c5

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

src/tools/miri/tests/fail/concurrency/mutex-leak-move-deadlock.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//@error-in-other-file: deadlock
2+
//@ignore-target: linux
23
//@normalize-stderr-test: "src/sys/.*\.rs" -> "$$FILE"
34
//@normalize-stderr-test: "LL \| .*" -> "LL | $$CODE"
45
//@normalize-stderr-test: "\| +\^+" -> "| ^"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//@only-target: linux
2+
//@normalize-stderr-test: "src/sys/.*\.rs" -> "$$FILE"
3+
//@normalize-stderr-test: "LL \| .*" -> "LL | $$CODE"
4+
//@normalize-stderr-test: "\| +\^+" -> "| ^"
5+
//@normalize-stderr-test: "\n *= note:.*" -> ""
6+
use std::mem;
7+
use std::sync::Mutex;
8+
9+
fn main() {
10+
let m = Mutex::new(0);
11+
mem::forget(m.lock());
12+
// Move the lock while it is "held" (really: leaked)
13+
let m2 = m;
14+
// Now try to acquire the lock again.
15+
let _guard = m2.lock();
16+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
thread 'main' panicked at RUSTLIB/std/$FILE:LL:CC:
2+
failed to lock mutex: Os { code: 35, kind: Deadlock, message: "deadlock" }
3+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
4+
note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect

0 commit comments

Comments
 (0)