-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Joining thread in thread local storage destructor never returns on Windows #74875
Comments
This is specifically about TLS destructors of the main thread, right? That one is kind of dubious anyway: #28129. Does this also happen when it's not the main thread's dtors? |
Cc @mati865 |
In my example, the TLS destructor is called from within the spawned thread AFAIK, not the main thread. Even if I move the |
I stepped a bit through libstd from my example. The thread spawned from It looks like Windows isn't aware that the thread actually ended... 🤔 |
Hm good point, the main thread never uses |
I can only confirm this hangs with both MinGW and MSVC in the line linked by emgre. @RalfJung you should call Windows WG. |
@rustbot ping windows |
Hey Windows Group! This bug has been identified as a good "Windows candidate". cc @arlosi @danielframpton @gdr-at-ms @kennykerr @luqmana @lzybkr @retep998 @rylev @sivadeilra |
|
@retep998 I don't think there's a join on the current thread anywhere here? |
Hmmm, I'll have to investigate further into what is going on... |
There's definitely race conditions involved as inserting sleeps at certain points changes the behavior. |
This excerpt from MSDN might be relevant:
|
The destructors are being run during the thread local callback function. This in turn will run during thread or module exit. During this time the OS holds a loader lock which, to cut a long story short, makes using any kind of thread synchronization prone to deadlock. For more details see Dynamic-Link Library Best Practices (it's talking about DllMain but it's mostly applicable to the tls callback too). I don't think this is fixable by Rust other than to say "don't do that". |
…olnay Document Windows TLS drop behaviour The way Windows TLS destructors are run has some "interesting" properties. They should be documented. Fixes rust-lang#74875
The following code never returns on Windows. The console never prints
Done
, and sometimes theStart thread
andEnd thread
are also not even printed. On Linux, it runs as expected.(Playground)
Output:
Errors:
My guess is that this wizardry is in cause:
rust/library/std/src/sys/windows/thread_local_key.rs
Lines 1 to 252 in 2c28244
The text was updated successfully, but these errors were encountered: