about summary refs log tree commit diff
path: root/src/libstd/thread
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-08-09 07:30:14 +0000
committerbors <bors@rust-lang.org>2018-08-09 07:30:14 +0000
commitfbb6275f4fd6cf774e1789fabfacae7248c45021 (patch)
treef66469baf6a3a33dad86eb02c203c66115a816bb /src/libstd/thread
parent76b69a604ee0d70be1edfa2828c769dc1b148d13 (diff)
parent25db84206b681731960d88558bc53640fe117b09 (diff)
downloadrust-fbb6275f4fd6cf774e1789fabfacae7248c45021.tar.gz
rust-fbb6275f4fd6cf774e1789fabfacae7248c45021.zip
Auto merge of #53108 - RalfJung:mutex, r=alexcrichton
clarify partially initialized Mutex issues

Using a `sys_common::mutex::Mutex` without calling `init` is dangerous, and yet there are some places that do this. I tried to find all of them and add an appropriate comment about reentrancy.

I found two places where (I think) reentrancy can actually occur, and was not able to come up with an argument for why this is okay. Someone who knows `io::lazy` and/or `sys_common::at_exit_imp` should have a careful look at this.
Diffstat (limited to 'src/libstd/thread')
-rw-r--r--src/libstd/thread/mod.rs2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs
index bbe80df7e8b..61c6084a250 100644
--- a/src/libstd/thread/mod.rs
+++ b/src/libstd/thread/mod.rs
@@ -940,6 +940,8 @@ pub struct ThreadId(u64);
 impl ThreadId {
     // Generate a new unique thread ID.
     fn new() -> ThreadId {
+        // We never call `GUARD.init()`, so it is UB to attempt to
+        // acquire this mutex reentrantly!
         static GUARD: mutex::Mutex = mutex::Mutex::new();
         static mut COUNTER: u64 = 0;