diff options
| author | Ralf Jung <post@ralfj.de> | 2018-08-06 14:39:55 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2018-08-06 14:39:55 +0200 |
| commit | 645388583ca47357a6a2e5878a9cde84e2e579d3 (patch) | |
| tree | b540ad370e3d571608473073de8de219bda2aff9 /src/libstd/sys_common | |
| parent | ab3e4a27894295ec0fca28b492450f2b22fbad4e (diff) | |
| download | rust-645388583ca47357a6a2e5878a9cde84e2e579d3.tar.gz rust-645388583ca47357a6a2e5878a9cde84e2e579d3.zip | |
actually, reentrant uninitialized mutex acquisition is outright UB
Diffstat (limited to 'src/libstd/sys_common')
| -rw-r--r-- | src/libstd/sys_common/at_exit_imp.rs | 5 | ||||
| -rw-r--r-- | src/libstd/sys_common/mutex.rs | 6 | ||||
| -rw-r--r-- | src/libstd/sys_common/thread_local.rs | 5 |
3 files changed, 7 insertions, 9 deletions
diff --git a/src/libstd/sys_common/at_exit_imp.rs b/src/libstd/sys_common/at_exit_imp.rs index 30019088eb6..85679837312 100644 --- a/src/libstd/sys_common/at_exit_imp.rs +++ b/src/libstd/sys_common/at_exit_imp.rs @@ -23,9 +23,8 @@ type Queue = Vec<Box<dyn FnBox()>>; // on poisoning and this module needs to operate at a lower level than requiring // the thread infrastructure to be in place (useful on the borders of // initialization/destruction). -// `LOCK` is never initialized fully, so this mutex is reentrant! -// Do not use it in a way that might be reentrant, that could lead to -// aliasing `&mut`. +// `LOCK` is never initialized fully, so it is UB to attempt to +// acquire this mutex reentrantly! static LOCK: Mutex = Mutex::new(); static mut QUEUE: *mut Queue = ptr::null_mut(); diff --git a/src/libstd/sys_common/mutex.rs b/src/libstd/sys_common/mutex.rs index a4efe4d128e..74e1defd9f4 100644 --- a/src/libstd/sys_common/mutex.rs +++ b/src/libstd/sys_common/mutex.rs @@ -24,9 +24,9 @@ impl Mutex { /// /// Behavior is undefined if the mutex is moved after it is /// first used with any of the functions below. - /// Also, the mutex might not be fully functional without calling - /// `init`! For example, on unix, the mutex is reentrant - /// until `init` reconfigures it appropriately. + /// Also, until `init` is called, behavior is undefined if this + /// mutex is ever used reentrantly, i.e., `raw_lock` or `try_lock` + /// are called by the thread currently holding the lock. pub const fn new() -> Mutex { Mutex(imp::Mutex::new()) } /// Prepare the mutex for use. diff --git a/src/libstd/sys_common/thread_local.rs b/src/libstd/sys_common/thread_local.rs index 2cc5372e268..9db7d732698 100644 --- a/src/libstd/sys_common/thread_local.rs +++ b/src/libstd/sys_common/thread_local.rs @@ -161,9 +161,8 @@ impl StaticKey { // Additionally a 0-index of a tls key hasn't been seen on windows, so // we just simplify the whole branch. if imp::requires_synchronized_create() { - // `INIT_LOCK` is never initialized fully, so this mutex is reentrant! - // Do not use it in a way that might be reentrant, that could lead to - // aliasing `&mut`. + // `INIT_LOCK` is never initialized fully, so it is UB to attempt to + // acquire this mutex reentrantly! static INIT_LOCK: Mutex = Mutex::new(); let _guard = INIT_LOCK.lock(); let mut key = self.key.load(Ordering::SeqCst); |
