Skip to content

Commit ebc4004

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 2c243d9 + e055e1c commit ebc4004

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
//@ ignore-android android does not seem to run dtors on the main thread (issue #126858)
6+
//! Ensure that TLS destructors run on the main thread.
7+
8+
struct Bar;
9+
10+
impl Drop for Bar {
11+
fn drop(&mut self) {
12+
println!("Bar dtor");
13+
}
14+
}
15+
16+
struct Foo;
17+
18+
impl Drop for Foo {
19+
fn drop(&mut self) {
20+
println!("Foo dtor");
21+
// We initialize another thread-local inside the dtor, which is an interesting corner case.
22+
thread_local!(static BAR: Bar = Bar);
23+
BAR.with(|_| {});
24+
}
25+
}
26+
27+
thread_local!(static FOO: Foo = Foo);
28+
29+
fn main() {
30+
FOO.with(|_| {});
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Foo dtor
2+
Bar dtor

0 commit comments

Comments
 (0)