We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0b7cdf2 commit 85a4907Copy full SHA for 85a4907
library/std/src/thread/mod.rs
@@ -1307,14 +1307,13 @@ impl ThreadId {
1307
1308
// SAFETY: we have an exclusive lock on the counter.
1309
unsafe {
1310
- if *COUNTER.get() == u64::MAX {
1311
- COUNTER_LOCKED.store(false, Ordering::Release);
1312
- exhausted()
1313
- } else {
1314
- let id = *COUNTER.get() + 1;
+ if let Some(id) = (*COUNTER.get()).checked_add(1) {
1315
*COUNTER.get() = id;
1316
COUNTER_LOCKED.store(false, Ordering::Release);
1317
ThreadId(NonZero::new(id).unwrap())
+ } else {
+ COUNTER_LOCKED.store(false, Ordering::Release);
+ exhausted()
1318
}
1319
1320
0 commit comments