线程不能被子进程继承
写一个并行服务器程序发现总是不能成功,调了很久才发现这个问题,
最后把fork()放在创建thread前面就把问题解决了,mark
man 一下fork 中有一段
The child process is created with a single thread — the one that
called fork(). The entire virtual address space of the parent is
replicated in the child, including the states of mutexes, condition
variables, and other pthreads objects; the use of pthread_atfork(3)
may be helpful for dealing with problems that this can cause.
called fork(). The entire virtual address space of the parent is
replicated in the child, including the states of mutexes, condition
variables, and other pthreads objects; the use of pthread_atfork(3)
may be helpful for dealing with problems that this can cause.
子进程由调用fork()的线程创建,并且只复制这个线程到子进程,并不复制fork()以外的线程.
这个模型在<<sun多线程编程指南>>中称为Fork-one模型,这个模型有安全问题
,在<<sun多线程编程指南>>有详细的解决方法。