From 2750d3ac6a4f6015a7a9720b8fbcb3610aa691e1 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 9 Jul 2021 20:50:08 +0200 Subject: [PATCH 1/2] avoid reentrant lock acquire when ThreadIds run out --- library/std/src/thread/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index da2d11604934f..5630904da77b7 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -1004,6 +1004,7 @@ impl ThreadId { // If we somehow use up all our bits, panic so that we're not // covering up subtle bugs of IDs being reused. if COUNTER == u64::MAX { + drop(_guard); // in case the panic handler ends up calling `ThreadId::new()`, avoid reentrant lock acquire. panic!("failed to generate unique thread ID: bitspace exhausted"); } From dbc2b55baf2e6124bedea62d4ec67ab212a57b85 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 10 Jul 2021 14:14:09 +0200 Subject: [PATCH 2/2] rename variable --- library/std/src/thread/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index 5630904da77b7..9f7e6b95dfb90 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -999,12 +999,12 @@ impl ThreadId { static mut COUNTER: u64 = 1; unsafe { - let _guard = GUARD.lock(); + let guard = GUARD.lock(); // If we somehow use up all our bits, panic so that we're not // covering up subtle bugs of IDs being reused. if COUNTER == u64::MAX { - drop(_guard); // in case the panic handler ends up calling `ThreadId::new()`, avoid reentrant lock acquire. + drop(guard); // in case the panic handler ends up calling `ThreadId::new()`, avoid reentrant lock acquire. panic!("failed to generate unique thread ID: bitspace exhausted"); }