You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix Windows preemptive crash: two-level preemption to avoid RefCell contention
The SuspendThread-based preemption can fire at any instruction, including
during println!() which holds the test harness's OUTPUT_CAPTURE RefCell.
When another coroutine on the same thread tries println!, it causes a
double-panic abort (STATUS_STACK_BUFFER_OVERRUN / STATUS_HEAP_CORRUPTION).
Fix: Implement two-level preemption:
- Level 1: First SuspendThread sets a thread-local flag and returns
without switching coroutines. preempt_asm restores all registers and
returns to the original code.
- Level 2: If the flag is still set at the next SuspendThread (~1ms
later), the coroutine is truly CPU-bound — force immediate suspend.
- Cooperative yield: check_preempt() called from Windows impl_facade!
after each hooked syscall, yielding at a safe point where no
thread-local borrows are held.
This ensures coroutines with syscalls (like Sleep in the preemptive
example) yield cooperatively at safe points, while pure CPU-bound loops
(like loop{}) still get force-preempted after one extra monitor cycle.
Agent-Logs-Url: https://github.com/acl-dev/open-coroutine/sessions/32977241-0cd1-450d-9693-d17d06f87274
Co-authored-by: loongs-zhang <38336731+loongs-zhang@users.noreply.github.com>
0 commit comments