このへんの資料みながら。
SUSによると、マルチスレッドプログラムはforkしたあと、async-signal-safeオペレーションしか、しちゃダメということになっている。
特に glibc とかだと、規格を守らない奴がバカ。ってスタンスなので、libc 呼び出し中にforkしたらハングしても文句はいえない。
libc の中でmutex使っていけないというルールはないから。
http://www.opengroup.org/onlinepubs/009695399/functions/fork.html
A process shall be created with a single thread. If a multi-threaded process calls fork(), the new process shall contain a replica of the calling thread and its entire address space, possibly including the states of mutexes and other resources. Consequently, to avoid errors, the child process may only execute async-signal-safe operations until such time as one of the exec functions is called. [THR] [Option Start] Fork handlers may be established by means of the pthread_atfork() function in order to maintain application invariants across fork() calls. [Option End]
When the application calls fork() from a signal handler and any of the fork handlers registered by pthread_atfork() calls a function that is not asynch-signal-safe, the behavior is undefined.
要約:
fork時はスレッドは呼び出しスレッドしかコピーされない。でもmutexやらなんやらの状態はコピーされてしまう。必然的にexecute async-signal-safe な操作しかしちゃだめってこった。
でも、実際問題として、世の中には規格を調べない人がいっぱいいるので・・・