mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-01 07:33:12 +08:00
fork() copies only the calling thread, so a child forked while the allocator's prefault helper held scr_sa_pf_lock waited on that lock forever at its first fault-in request, and a child that released the range the helper was faulting in waited forever for the helper to finish it. Native builds' emit workers hung this way, with the parent waiting in waitpid. The helper's first start now registers pthread_atfork handlers. The prepare handler takes the lock across the fork and the parent handler releases it. The child handler resets the ring, the busy range, the waiter state and the heap polling state, reinitializes the lock and both conditions, and marks the helper not started, so the child's first request starts a helper of its own. check_fork_while_prefaulting in scr_alloc.test.c forks while the helper faults in 64 MiB, over 64 rounds; each child releases that range, faults in a range of its own and must exit within five seconds. ThreadSanitizer builds skip it.