about summary refs log tree commit diff
path: root/library/std/src/thread/local.rs
diff options
context:
space:
mode:
authorChris Denton <christophersdenton@gmail.com>2021-12-02 13:52:35 +0000
committerChris Denton <christophersdenton@gmail.com>2021-12-02 14:17:58 +0000
commit7a145250c6b23cb1bc361e1a8dae465720c46706 (patch)
tree2f6b23058e7d67c29edff793c8f95a391231a917 /library/std/src/thread/local.rs
parentd9baa361902b172be716f96619b909f340802dea (diff)
downloadrust-7a145250c6b23cb1bc361e1a8dae465720c46706.tar.gz
rust-7a145250c6b23cb1bc361e1a8dae465720c46706.zip
Document Windows TLS drop behaviour
Diffstat (limited to 'library/std/src/thread/local.rs')
-rw-r--r--library/std/src/thread/local.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/library/std/src/thread/local.rs b/library/std/src/thread/local.rs
index 4da59577d78..64c8416b61c 100644
--- a/library/std/src/thread/local.rs
+++ b/library/std/src/thread/local.rs
@@ -76,7 +76,21 @@ use crate::fmt;
 ///    destroyed, but not all platforms have this guard. Those platforms that do
 ///    not guard typically have a synthetic limit after which point no more
 ///    destructors are run.
+/// 3. When the process exits on Windows systems, TLS destructors may only be
+///    run on the thread that causes the process to exit. This is because the
+///    other threads may be forcibly terminated.
 ///
+/// ## Synchronization in thread-local destructors
+///
+/// On Windows, synchronization operations (such as [`JoinHandle::join`]) in
+/// thread local destructors are prone to deadlocks and so should be avoided.
+/// This is because the [loader lock] is held while a destructor is run. The
+/// lock is acquired whenever a thread starts or exits or when a DLL is loaded
+/// or unloaded. Therefore these events are blocked for as long as a thread
+/// local destructor is running.
+///
+/// [loader lock]: https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-best-practices
+/// [`JoinHandle::join`]: crate::thread::JoinHandle::join
 /// [`with`]: LocalKey::with
 #[stable(feature = "rust1", since = "1.0.0")]
 pub struct LocalKey<T: 'static> {