(vm: &VirtualMachine)
| 424 | /// Cleanup thread slot for the current thread. Called at thread exit. |
| 425 | #[cfg(feature = "threading")] |
| 426 | pub fn cleanup_current_thread_frames(vm: &VirtualMachine) { |
| 427 | let thread_id = crate::stdlib::_thread::get_ident(); |
| 428 | let current_slot = CURRENT_THREAD_SLOT.with(|slot| slot.borrow().as_ref().cloned()); |
| 429 | |
| 430 | // A dying thread should not remain logically ATTACHED while its |
| 431 | // thread-state slot is being removed. |
| 432 | #[cfg(all(unix, feature = "threading"))] |
| 433 | if let Some(slot) = ¤t_slot { |
| 434 | let _ = slot.state.compare_exchange( |
| 435 | THREAD_ATTACHED, |
| 436 | THREAD_DETACHED, |
| 437 | Ordering::AcqRel, |
| 438 | Ordering::Acquire, |
| 439 | ); |
| 440 | } |
| 441 | |
| 442 | // Guard against OS thread-id reuse races: only remove the registry entry |
| 443 | // if it still points at this thread's own slot. |
| 444 | let removed = if let Some(slot) = ¤t_slot { |
| 445 | let mut registry = vm.state.thread_frames.lock(); |
| 446 | match registry.get(&thread_id) { |
| 447 | Some(registered) if Arc::ptr_eq(registered, slot) => registry.remove(&thread_id), |
| 448 | _ => None, |
| 449 | } |
| 450 | } else { |
| 451 | None |
| 452 | }; |
| 453 | #[cfg(all(unix, feature = "threading"))] |
| 454 | if let Some(slot) = &removed |
| 455 | && vm.state.stop_the_world.requested.load(Ordering::Acquire) |
| 456 | && thread_id != vm.state.stop_the_world.requester_ident() |
| 457 | && slot.state.load(Ordering::Relaxed) != THREAD_SUSPENDED |
| 458 | { |
| 459 | // A non-requester thread disappeared while stop-the-world is pending. |
| 460 | // Unblock requester countdown progress. |
| 461 | vm.state.stop_the_world.notify_thread_gone(); |
| 462 | } |
| 463 | CURRENT_THREAD_SLOT.with(|s| { |
| 464 | *s.borrow_mut() = None; |
| 465 | }); |
| 466 | } |
| 467 | |
| 468 | /// Reinitialize thread slot after fork. Called in child process. |
| 469 | /// Creates a fresh slot and registers it for the current thread, |
no test coverage detected