develooper Front page | perl.ithreads | Postings from March 2013

Re: Issues with process forking when 'multithreaded'.

Thread Previous | Thread Next
Dave Mitchell
March 4, 2013 17:00
Re: Issues with process forking when 'multithreaded'.
Message ID:
On Mon, Mar 04, 2013 at 04:32:13PM +0100, Sander Smeenk wrote:
> So, it's not a fork() from the main process (which would perhaps
> copy all threads to the fork()ed process, or maybe not, who knows).

fork() on linux creates a single thread in the child process, but copies
the memory and state of *all* threads. Which is why you can get in a right
mess. For example, if one of the other threads had something locked, that
will be still be locked in the new process, but without a corresponding
thread still running that can unlock it. So the forked process might
deadlock or otherwise behave strangely.

This is why people say not to mix threads and forks.

My Dad used to say 'always fight fire with fire', which is probably why
he got thrown out of the fire brigade.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About