Fix a dangling reference in rustc_thread_pool
This commit is contained in:
parent
e10aa88911
commit
389a502ade
1 changed files with 6 additions and 2 deletions
|
|
@ -388,13 +388,17 @@ impl Latch for CountLatch {
|
|||
#[inline]
|
||||
unsafe fn set(this: *const Self) {
|
||||
if unsafe { (*this).counter.fetch_sub(1, Ordering::SeqCst) == 1 } {
|
||||
// NOTE: Once we call `set` on the internal `latch`,
|
||||
// SAFETY: Once we call `set` on the internal `latch`,
|
||||
// the target may proceed and invalidate `this`!
|
||||
match unsafe { &(*this).kind } {
|
||||
CountLatchKind::Stealing { latch, registry, worker_index } => {
|
||||
let registry = Arc::clone(registry);
|
||||
let worker_index = *worker_index;
|
||||
// SAFETY: We don't use any references from `this` after this call.
|
||||
if unsafe { CoreLatch::set(latch) } {
|
||||
registry.notify_worker_latch_is_set(*worker_index);
|
||||
// We **must not** access any part of `this` anymore, which
|
||||
// is why we read and shadowed these fields beforehand.
|
||||
registry.notify_worker_latch_is_set(worker_index);
|
||||
}
|
||||
}
|
||||
CountLatchKind::Blocking { latch } => unsafe { LockLatch::set(latch) },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue