Re: using pthreads with fork() in linux



"Maxim Yegorushkin" <maxim.yegorushkin@xxxxxxxxx> wrote in message
news:1148982325.315534.311840@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Arnold Hendriks wrote:

For one, you should only use async-signal-safe functions after fork(),
until
you exec().

This is wrong. You are probably talking about vfork().
This is why there is pthread_atfork.
http://www.opengroup.org/onlinepubs/009695399/functions/pthread_atfork.html

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.



.



Relevant Pages

  • Re: using pthreads with fork() in linux
    ... A process shall be created with a single thread. ... calls fork(), the new process shall contain a replica of the calling thread ... POSIX operation depends on the implementation of that operation and what ... internal resources it uses, which you don't know. ...
    (comp.programming.threads)
  • Re: using pthreads with fork() in linux
    ... A process shall be created with a single thread. ... It may only be a recommendation, but it's pretty much an unavoidable one. ... If it were as you say fork() would be pretty much useless. ... This is how apache prior ...
    (comp.programming.threads)
  • Re: Fork or threads
    ... >to actually read in the whole file, multiple files, this could be anywhere ... >Should I fork off an X amount of processes to do this? ... process having a single thread seems sufficient given this level of info. ...
    (comp.unix.programmer)
  • Re: using pthreads with fork() in linux
    ... A process shall be created with a single thread. ... If a multi-threaded process ... This is only a recommendation how to avoid errors when a multithreaded ... program forks. ...
    (comp.programming.threads)