The following deadlock scenario looks like a bug in glibc.
* Calls fork() which runs pthread_atfork handlers.
* Malloc's registered handler runs and locks out all other
threads from doing allocations by causing them to block.
* Tries to take the IO list lock via _IO_list_lock()
* Calls _IO_flush_all()
-> _IO_flush_all_lockp (do_lock=1)
-> _IO_lock_lock (list_all_lock); ...
* Walks the list of open fp's and tries to take each
fp's lock and flush.
* Calls _IO_getdelim which takes only the fp lock
and then tries to call either malloc or realloc.
* Tries to take arena lock to allocate memory.
So in summary:
Thread A waits on thread B for the list_all_lock lock.
Thread B waits on thread C for the fp file lock.
Thread C waits on thread A for the arena lock.