mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-11-07 13:39:55 +00:00
The macOS write watch serialized its fault handler and collections with a ticket lock whose waiters spin on sched_yield. When the thread holding the next turn is not running, every other thread waits behind it even though the lock is free, so with more runnable threads than cores the handoffs stall. write_watch_threads took 6.75 s and then timed out at 30 s on the macos-15-intel runner in run 39151604364, a run whose pull request does not touch the write watch. The lock is now a pthread mutex with the first-fit policy: a waiter blocks in the kernel, and the mutex goes to whichever thread takes it first instead of to the next turn in line. The ticket lock was there so that a thread collecting in a loop cannot starve writers waiting in the handler. That is kept by giving the handler precedence: a collection and every other entry point wait on a condition variable while a fault is waiting for the mutex or holding it. Faults cannot starve them in turn, since a fault lifts the protection of a page and only those entry points protect pages again.