Skip to content

Commit 461facc

Browse files
fixup! Fix data race in thread::scope()
1 parent 908017f commit 461facc

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

library/std/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@
291291
#![feature(std_internals)]
292292
#![feature(str_internals)]
293293
#![feature(strict_provenance)]
294+
#![feature(sync_unsafe_cell)]
294295
//
295296
// Library features (alloc):
296297
#![feature(alloc_layout_extra)]

library/std/src/thread/scoped.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ pub struct ScopedJoinHandle<'scope, T>(JoinInner<'scope, T>);
4141
pub(super) struct ScopeData {
4242
num_running_threads: AtomicUsize,
4343
a_thread_panicked: AtomicBool,
44-
main_thread: UnsafeCell<Thread>,
44+
// SAFETY: `ScopeData` is `&`-shared by all the scoped threads, with no
45+
// mutation whatsoever, except when `num_running_threads` drops down to `0`,
46+
// which is when the main thread's `scope()` may deallocate this data.
47+
main_thread: crate::cell::SyncUnsafeCell<Thread>,
4548
}
4649

4750
impl ScopeData {

0 commit comments

Comments
 (0)