forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
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#126829 - RalfJung:main-thread-tls, r=workingj…
…ubilee add test for main thread thread-local destructors Fixes rust-lang#28129
- Loading branch information
Showing
2 changed files
with
33 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//@ run-pass | ||
//@ check-run-results | ||
//@ needs-threads (really only needs TLS, not threads, but those seem to usually come together) | ||
//@ ignore-musl musl does not seem to run dtors on the main thread (issue #126858) | ||
//@ ignore-android android does not seem to run dtors on the main thread (issue #126858) | ||
//! Ensure that TLS destructors run on the main thread. | ||
|
||
struct Bar; | ||
|
||
impl Drop for Bar { | ||
fn drop(&mut self) { | ||
println!("Bar dtor"); | ||
} | ||
} | ||
|
||
struct Foo; | ||
|
||
impl Drop for Foo { | ||
fn drop(&mut self) { | ||
println!("Foo dtor"); | ||
// We initialize another thread-local inside the dtor, which is an interesting corner case. | ||
thread_local!(static BAR: Bar = Bar); | ||
BAR.with(|_| {}); | ||
} | ||
} | ||
|
||
thread_local!(static FOO: Foo = Foo); | ||
|
||
fn main() { | ||
FOO.with(|_| {}); | ||
} |
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,2 @@ | ||
Foo dtor | ||
Bar dtor |