CRASH from race between detach and a new thread
Detach on UNIX has a race where a new thread can have been created but not yet been added to the DR thread list at the point where detach does its synchall. The new thread will wait on thread_initexit_lock while detach proceeds and finishes. The new thread is on the dstack, and will proceed to use other resources, after detach has freed them.
Windows has a partial solution to this via its init_apc_go_native flags but technically still has a race window.
Trying to solve this once the child is created is complex and seems to require extra synch steps. I'm proposing a solution that is folded into the synchall process using a count parallel to the existing exiting_thread_count.