Skip to content

Commit 1deb487

Browse files
committed
thread::scope: document how join interacts with TLS destructors
1 parent 91ab308 commit 1deb487

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

library/std/src/thread/join_handle.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ impl<T> JoinHandle<T> {
102102
/// Waits for the associated thread to finish.
103103
///
104104
/// This function will return immediately if the associated thread has already finished.
105+
/// Otherwise, it fully waits for the thread to finish, including all destructors
106+
/// for thread-local variables that might be running after the main function of the thread.
105107
///
106108
/// In terms of [atomic memory orderings], the completion of the associated
107109
/// thread synchronizes with this function returning. In other words, all

library/std/src/thread/scoped.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ impl ScopeData {
8080
///
8181
/// All threads spawned within the scope that haven't been manually joined
8282
/// will be automatically joined before this function returns.
83+
/// However, note that joining will only wait for the main function of these threads to finish; even
84+
/// when this function returns, destructors of thread-local variables in these threads might still
85+
/// be running.
8386
///
8487
/// # Panics
8588
///
@@ -292,6 +295,8 @@ impl<'scope, T> ScopedJoinHandle<'scope, T> {
292295
/// Waits for the associated thread to finish.
293296
///
294297
/// This function will return immediately if the associated thread has already finished.
298+
/// Otherwise, it fully waits for the thread to finish, including all destructors
299+
/// for thread-local variables that might be running after the main function of the thread.
295300
///
296301
/// In terms of [atomic memory orderings], the completion of the associated
297302
/// thread synchronizes with this function returning.

0 commit comments

Comments
 (0)