Files
AnyPS5/core
Jota 42fb02cdba fix(libc): let the macOS write watch fault handler go first
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.
2026-10-18 21:31:37 -03:00
..