forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
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 rust-lang#3501 - RalfJung:tls-many-seeds, r=RalfJung
add a test for the TLS memory leak This is a regression test for rust-lang#123583.
- Loading branch information
Showing
4 changed files
with
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//! Regression test for <https://github.com/rust-lang/rust/issues/123583>. | ||
use std::thread; | ||
|
||
fn with_thread_local1() { | ||
thread_local! { static X: Box<u8> = Box::new(0); } | ||
X.with(|_x| {}) | ||
} | ||
|
||
fn with_thread_local2() { | ||
thread_local! { static Y: Box<u8> = Box::new(0); } | ||
Y.with(|_y| {}) | ||
} | ||
|
||
fn main() { | ||
// Here we have two threads racing on initializing the thread-local and adding it to the global | ||
// dtor list (on targets that have such a list, i.e., targets without target_thread_local). | ||
let t = thread::spawn(with_thread_local1); | ||
with_thread_local1(); | ||
t.join().unwrap(); | ||
|
||
// Here we have one thread running the destructors racing with another thread initializing a | ||
// thread-local. The second thread adds a destructor that could be picked up by the first. | ||
let t = thread::spawn(|| { /* immediately just run destructors */ }); | ||
with_thread_local2(); // initialize thread-local | ||
t.join().unwrap(); | ||
} |