Skip to content

Commit 7a14525

Browse files
committed
Document Windows TLS drop behaviour
1 parent d9baa36 commit 7a14525

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

library/std/src/thread/local.rs

+14
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,21 @@ use crate::fmt;
7676
/// destroyed, but not all platforms have this guard. Those platforms that do
7777
/// not guard typically have a synthetic limit after which point no more
7878
/// destructors are run.
79+
/// 3. When the process exits on Windows systems, TLS destructors may only be
80+
/// run on the thread that causes the process to exit. This is because the
81+
/// other threads may be forcibly terminated.
7982
///
83+
/// ## Synchronization in thread-local destructors
84+
///
85+
/// On Windows, synchronization operations (such as [`JoinHandle::join`]) in
86+
/// thread local destructors are prone to deadlocks and so should be avoided.
87+
/// This is because the [loader lock] is held while a destructor is run. The
88+
/// lock is acquired whenever a thread starts or exits or when a DLL is loaded
89+
/// or unloaded. Therefore these events are blocked for as long as a thread
90+
/// local destructor is running.
91+
///
92+
/// [loader lock]: https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-best-practices
93+
/// [`JoinHandle::join`]: crate::thread::JoinHandle::join
8094
/// [`with`]: LocalKey::with
8195
#[stable(feature = "rust1", since = "1.0.0")]
8296
pub struct LocalKey<T: 'static> {

0 commit comments

Comments
 (0)