Skip to content

Commit

Permalink
Auto merge of rust-lang#126829 - RalfJung:main-thread-tls, r=workingj…
Browse files Browse the repository at this point in the history
…ubilee

add test for main thread thread-local destructors

Fixes rust-lang#28129
  • Loading branch information
bors committed Jun 23, 2024
2 parents c3d7fb3 + 5d7718d commit 0109de7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/ui/thread-local/main-thread-dtor.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//@ 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)
//! 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(|_| {});
}
2 changes: 2 additions & 0 deletions tests/ui/thread-local/main-thread-dtor.run.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Foo dtor
Bar dtor

0 comments on commit 0109de7

Please sign in to comment.