Subject: Re: fork(2) vs. pthread_create() (fwd)
To: Emmanuel Dreyfus <email@example.com>
From: Giles Lean <firstname.lastname@example.org>
Date: 06/09/2004 18:57:52
Emmanuel Dreyfus <email@example.com> wrote:
> Before forking, I joined the exisiting thread, thus reverting to a single
> threaded process. The problem is that the process remebers it has been
> threaded when I hit the fork, whereas it is not threaded anymore.
You expect libc to undo any initialisation that it did when the second
last thread in a process exits?
Postponing initialisation of locks for a multithreaded process is good:
many Unix processes remain single threaded. Undoing this work for a
process that has been multithreaded isn't an obvious win; such processes
are rather likely to spawn more threads, surely?
I would think of your example as a multithreaded process that currently
only had one thread. :-|
fork() sits really unhappily with the POSIX threads model. I am sure if
the POSIX threads folk could have they would have outlawed fork() in
multithreaded processes, but that's just not practical on Unix (er,
POSIX :-) systems.