-
Notifications
You must be signed in to change notification settings - Fork 356
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 #1858 - RalfJung:thread-leaks, r=oli-obk
also ignore 'thread leaks' with -Zmiri-ignore-leaks This is a step towards #1371. The remaining hard part would be supporting checking for memory leaks when there are threads still running. For now we elegantly avoid this problem by using the same flag to control both of these checks. :)
- Loading branch information
Showing
6 changed files
with
66 additions
and
12 deletions.
There are no files selected for viewing
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,37 @@ | ||
// ignore-windows: Concurrency on Windows is not supported yet. | ||
// compile-flags: -Zmiri-ignore-leaks | ||
|
||
//! Test that leaking threads works, and that their destructors are not executed. | ||
use std::cell::RefCell; | ||
|
||
struct LoudDrop(i32); | ||
impl Drop for LoudDrop { | ||
fn drop(&mut self) { | ||
eprintln!("Dropping {}", self.0); | ||
} | ||
} | ||
|
||
thread_local! { | ||
static X: RefCell<Option<LoudDrop>> = RefCell::new(None); | ||
} | ||
|
||
fn main() { | ||
X.with(|x| *x.borrow_mut() = Some(LoudDrop(0))); | ||
|
||
// Set up a channel so that we can learn when the other thread initialized `X` | ||
// (so that we are sure there is something to drop). | ||
let (send, recv) = std::sync::mpsc::channel::<()>(); | ||
|
||
let _detached = std::thread::spawn(move || { | ||
X.with(|x| *x.borrow_mut() = Some(LoudDrop(1))); | ||
send.send(()).unwrap(); | ||
std::thread::yield_now(); | ||
loop {} | ||
}); | ||
|
||
std::thread::yield_now(); | ||
|
||
// Wait until child thread has initialized its `X`. | ||
let () = recv.recv().unwrap(); | ||
} |
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,3 @@ | ||
warning: thread support is experimental and incomplete: weak memory effects are not emulated. | ||
|
||
Dropping 0 |