There are some platforms where TLS destructors are run when the main thread exits, and there are some platforms where this does not happen,~~ and there are some platforms where things just go crazy ~~. For example, testing this program:
struct Foo;
impl Drop for Foo {
fn drop(&mut self) {
println!("wut");
}
}
thread_local!(static FOO: Foo = Foo);
fn main() {
FOO.with(|_| {});
}
This should print Foo dtor, but prints nothing on some targets:
Here's a more complicated testcase that also involves initializing a destructor while destructors are being run; ideally this will be added to the test suite at some point:
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(|_| {});
}
some older notes
There are some platforms where TLS destructors are run when the main thread exits, and there are some platforms where this does not happen,~~ and there are some platforms where things just go crazy ~~. For example, testing this program:
This should print
Foo dtor, but prints nothing on some targets:Here's a more complicated testcase that also involves initializing a destructor while destructors are being run; ideally this will be added to the test suite at some point:
some older notes
appears to call destructors, but the program above specifically causes some form of memory corrupting, triggering an assert in mallocfixed by OSX: fix #57534 registering thread dtors while running thread dtors #57655notwork.We're listening forDLL_PROCESS_DETACHbut for some reason we're not getting that notification.