Skip to content

Commit 0109de7

Browse files
committed
Auto merge of rust-lang#126829 - RalfJung:main-thread-tls, r=workingjubilee
add test for main thread thread-local destructors Fixes rust-lang#28129
2 parents c3d7fb3 + 5d7718d commit 0109de7

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//@ run-pass
2+
//@ check-run-results
3+
//@ needs-threads (really only needs TLS, not threads, but those seem to usually come together)
4+
//@ ignore-musl musl does not seem to run dtors on the main thread (issue #126858)
5+
//! Ensure that TLS destructors run on the main thread.
6+
7+
struct Bar;
8+
9+
impl Drop for Bar {
10+
fn drop(&mut self) {
11+
println!("Bar dtor");
12+
}
13+
}
14+
15+
struct Foo;
16+
17+
impl Drop for Foo {
18+
fn drop(&mut self) {
19+
println!("Foo dtor");
20+
// We initialize another thread-local inside the dtor, which is an interesting corner case.
21+
thread_local!(static BAR: Bar = Bar);
22+
BAR.with(|_| {});
23+
}
24+
}
25+
26+
thread_local!(static FOO: Foo = Foo);
27+
28+
fn main() {
29+
FOO.with(|_| {});
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Foo dtor
2+
Bar dtor

0 commit comments

Comments
 (0)