Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 54762c9

Browse files
GnomedDevNoratrieb
andauthored
Add additional safety documentation
Co-authored-by: Nilstrieb <[email protected]>
1 parent 2c45b39 commit 54762c9

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

library/std/src/thread/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1312,7 +1312,10 @@ impl Inner {
13121312
fn parker(&self) -> Pin<&Parker> {
13131313
match self {
13141314
Self::Main => {
1315-
// Safety: MAIN_PARKER only ever has a mutable reference when Inner::Main is initialised.
1315+
// Safety: MAIN_PARKER is only ever read in this function, which requires access
1316+
// to an existing `&Inner` value, which can only be accessed via the main thread
1317+
// giving away such an instance from `current()`, implying that initialization,
1318+
// the only write to `MAIN_PARKER`, has been completed.
13161319
let static_ref: &'static MaybeUninit<Parker> = unsafe { &*MAIN_PARKER.get() };
13171320

13181321
// Safety: MAIN_PARKER is initialised when Inner::Main is initialised.

0 commit comments

Comments
 (0)