Chris Vine
2003-09-10 11:07:36 UTC
Hi,
A program I have relies on the parent thread which launches a new process
with fork() receiving (ie having its thread of execution asynchronously
interrupted by) the SIGBCHLD signal handler when the child terminates,
rather than that signal handler running in another thread's thread of
execution.
This is because the signal handler relies on certain variables not being
changed (except by itself) while it is executing. This can be guaranteed
if the signal handler executes in the thread of execution of the thread
which launched it, because (as the program is written) that is the only
thread which uses those variables. Of course if another thread can "pick
up" the signal and execute the signal handler, then that guarantee no
longer holds, because then the parent thread and its SIGCHLD handler could
be running concurrently. To deal with that I would have to put mutexes in
the signal handler.
Does POSIX/pthreads say anything about this, or is it implementation/OS
dependent? And does it make any difference if a new thread is a launched
by the parent process after the parent process starts a new process with
fork() (before the child process terminates)?
Chris.
A program I have relies on the parent thread which launches a new process
with fork() receiving (ie having its thread of execution asynchronously
interrupted by) the SIGBCHLD signal handler when the child terminates,
rather than that signal handler running in another thread's thread of
execution.
This is because the signal handler relies on certain variables not being
changed (except by itself) while it is executing. This can be guaranteed
if the signal handler executes in the thread of execution of the thread
which launched it, because (as the program is written) that is the only
thread which uses those variables. Of course if another thread can "pick
up" the signal and execute the signal handler, then that guarantee no
longer holds, because then the parent thread and its SIGCHLD handler could
be running concurrently. To deal with that I would have to put mutexes in
the signal handler.
Does POSIX/pthreads say anything about this, or is it implementation/OS
dependent? And does it make any difference if a new thread is a launched
by the parent process after the parent process starts a new process with
fork() (before the child process terminates)?
Chris.
--
To reply by e-mail, remove the "--nospam--" in the address
To reply by e-mail, remove the "--nospam--" in the address