Re: waitpid() thread race

2007-04-10 Thread Brian Candler
On Mon, Apr 09, 2007 at 03:42:50PM -0600, Philip Guenther wrote: However, OpenBSD 4.0 doesn't actually comply with that: after waitpid() there will be no SIGCHLD pending, even if there are additional children to reap. So, if you're going to have multiple children, you need to call

Re: waitpid() thread race

2007-04-09 Thread Brian Candler
On Sat, Apr 07, 2007 at 11:09:55AM -0600, Philip Guenther wrote: Instead of separating the obtaining of the pid from the actual reaping, you can instead separate the blocking from the return of the pid+reaping. That lets you lock the datastructure only when you know wait() won't block. To

Re: waitpid() thread race

2007-04-09 Thread Darrin Chandler
On Mon, Apr 09, 2007 at 09:10:39PM +0100, Brian Candler wrote: I'm not saying that anything is actually wrong with the code you've provided; rather, that it's difficult for me to understand the subtleties involved in asynchronous signal-driven programming. And that's with a copy of the Stevens

Re: waitpid() thread race

2007-04-09 Thread Philip Guenther
On 4/9/07, Brian Candler [EMAIL PROTECTED] wrote: ... Suppose child 1 dies, causing a SIGCHLD to be pending, and then a second child dies, before sigsuspend() unblocks the signal. sigsuspend returns, and one child is reaped. Next time around the loop, will the second child be reaped? If so, why?

Re: waitpid() thread race

2007-04-09 Thread Brian Candler
On Mon, Apr 09, 2007 at 01:40:06PM -0700, Darrin Chandler wrote: On Mon, Apr 09, 2007 at 09:10:39PM +0100, Brian Candler wrote: I'm not saying that anything is actually wrong with the code you've provided; rather, that it's difficult for me to understand the subtleties involved in

waitpid() thread race

2007-04-07 Thread Brian Candler
I have a question about the semantics of wait()/waitpid(). My understanding is, as soon as wait() returns, the process is gone from the process table, and therefore another fork() on the system could immediately re-use the same PID. Is that correct? Now let's suppose I have a program which forks

Re: waitpid() thread race

2007-04-07 Thread Darrin Chandler
On Sat, Apr 07, 2007 at 12:15:07PM +0100, Brian Candler wrote: I have a question about the semantics of wait()/waitpid(). My understanding is, as soon as wait() returns, the process is gone from the process table, and therefore another fork() on the system could immediately re-use the same

Re: waitpid() thread race

2007-04-07 Thread Philip Guenther
On 4/7/07, Brian Candler [EMAIL PROTECTED] wrote: ... Let's say there's a separate thread which blocks on a wait() call, and once it has gotten the pid it updates this data structure to remove the entry for pid Now, it seems to me there is a race condition here: between wait() returning and the