Skip to content

Commit 31bec78

Browse files
committed
avoid using the word 'initialized' to talk about that non-reentrant-capable state of the mutex
1 parent 6453885 commit 31bec78

File tree

7 files changed

+9
-8
lines changed

7 files changed

+9
-8
lines changed

src/libstd/io/lazy.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use sys_common;
1515
use sys_common::mutex::Mutex;
1616

1717
pub struct Lazy<T> {
18+
// We never call `lock.init()`, so it is UB to attempt to acquire this mutex reentrantly!
1819
lock: Mutex,
1920
ptr: Cell<*mut Arc<T>>,
2021
init: fn() -> Arc<T>,
@@ -29,8 +30,6 @@ impl<T: Send + Sync + 'static> Lazy<T> {
2930
/// Safety: `init` must not call `get` on the variable that is being
3031
/// initialized.
3132
pub const unsafe fn new(init: fn() -> Arc<T>) -> Lazy<T> {
32-
// `lock` is never initialized fully, so it is UB to attempt to
33-
// acquire this mutex reentrantly!
3433
Lazy {
3534
lock: Mutex::new(),
3635
ptr: Cell::new(ptr::null_mut()),

src/libstd/sys/unix/args.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ mod imp {
8080

8181
static mut ARGC: isize = 0;
8282
static mut ARGV: *const *const u8 = ptr::null();
83-
// `ENV_LOCK` is never initialized fully, so it is UB to attempt to
83+
// We never call `ENV_LOCK.init()`, so it is UB to attempt to
8484
// acquire this mutex reentrantly!
8585
static LOCK: Mutex = Mutex::new();
8686

src/libstd/sys/unix/os.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use sys::fd;
3333
use vec;
3434

3535
const TMPBUF_SZ: usize = 128;
36-
// `ENV_LOCK` is never initialized fully, so it is UB to attempt to
36+
// We never call `ENV_LOCK.init()`, so it is UB to attempt to
3737
// acquire this mutex reentrantly!
3838
static ENV_LOCK: Mutex = Mutex::new();
3939

src/libstd/sys_common/at_exit_imp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type Queue = Vec<Box<dyn FnBox()>>;
2323
// on poisoning and this module needs to operate at a lower level than requiring
2424
// the thread infrastructure to be in place (useful on the borders of
2525
// initialization/destruction).
26-
// `LOCK` is never initialized fully, so it is UB to attempt to
26+
// We never call `LOCK.init()`, so it is UB to attempt to
2727
// acquire this mutex reentrantly!
2828
static LOCK: Mutex = Mutex::new();
2929
static mut QUEUE: *mut Queue = ptr::null_mut();

src/libstd/sys_common/mutex.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ impl Mutex {
3232
/// Prepare the mutex for use.
3333
///
3434
/// This should be called once the mutex is at a stable memory address.
35-
/// Behavior is undefined unless this is called before any other operation.
35+
/// If called, this must be the very first thing that happens to the mutex.
36+
/// Calling it in parallel with or after any operation (including another
37+
/// `init()`) is undefined behavior.
3638
#[inline]
3739
pub unsafe fn init(&mut self) { self.0.init() }
3840

src/libstd/sys_common/thread_local.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl StaticKey {
161161
// Additionally a 0-index of a tls key hasn't been seen on windows, so
162162
// we just simplify the whole branch.
163163
if imp::requires_synchronized_create() {
164-
// `INIT_LOCK` is never initialized fully, so it is UB to attempt to
164+
// We never call `INIT_LOCK.init()`, so it is UB to attempt to
165165
// acquire this mutex reentrantly!
166166
static INIT_LOCK: Mutex = Mutex::new();
167167
let _guard = INIT_LOCK.lock();

src/libstd/thread/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ pub struct ThreadId(u64);
940940
impl ThreadId {
941941
// Generate a new unique thread ID.
942942
fn new() -> ThreadId {
943-
// `GUARD` is never initialized fully, so it is UB to attempt to
943+
// We never call `GUARD.init()`, so it is UB to attempt to
944944
// acquire this mutex reentrantly!
945945
static GUARD: mutex::Mutex = mutex::Mutex::new();
946946
static mut COUNTER: u64 = 0;

0 commit comments

Comments
 (0)