Skip to content

Commit 0ca5fc2

Browse files
authored
Rollup merge of #87011 - RalfJung:thread-id-supply-shortage, r=nagisa
avoid reentrant lock acquire when ThreadIds run out Discovered by `@bjorn3`
2 parents 632f84f + dbc2b55 commit 0ca5fc2

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

library/std/src/thread/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -999,11 +999,12 @@ impl ThreadId {
999999
static mut COUNTER: u64 = 1;
10001000

10011001
unsafe {
1002-
let _guard = GUARD.lock();
1002+
let guard = GUARD.lock();
10031003

10041004
// If we somehow use up all our bits, panic so that we're not
10051005
// covering up subtle bugs of IDs being reused.
10061006
if COUNTER == u64::MAX {
1007+
drop(guard); // in case the panic handler ends up calling `ThreadId::new()`, avoid reentrant lock acquire.
10071008
panic!("failed to generate unique thread ID: bitspace exhausted");
10081009
}
10091010

0 commit comments

Comments
 (0)