Boost logo

Boost :

From: Gregory Colvin (gregory.colvin_at_[hidden])
Date: 2004-06-22 20:13:59


On Jun 22, 2004, at 12:59 PM, Stefan Seefeld wrote:

> Gregory Colvin wrote:
>
>>> extern "C"
>>> void child_handler(int)
>>> {
>>> pid = wait(&status);
>>> std::map<pid_t, int>::iterator it =
>>> completed_children.find(pid);
>>> if (it != completed_children.end())
>>> it->second = status;
>>> }
>>>
>>> I'm pretty sure that the above is safe code.
>> It's unsafe because it's not reentrant.
>
> I believe to be truely reentrant yet flexible you'd need something more
> intrusive, such as a semaphore and then require the application to
> implement
> some checking, for example a callback that can be triggered from the
> main loop if ever the application has one.

Some platforms have sighold() and sigrelse(), but not all.

>> But why do you need to reap the zombie? I've implemented
>> the java process control natives with no need for reaping.
>
> I don't know how java deals with this but on posix platforms a
> sub-process
> holds some resources that have to be claimed back by the parent
> process.

Which you can do by waiting for the child. If you need the exit value
you might as well wait anyway, if you don't you create a thread to wait.

> This includes (but is not restricted to) the result of the process,
> i.e.
> its return value. In case you are familiar with (posix) threads: there
> you have to join a thread after it terminated. It's conceptually the
> same
> thing here.
>
> Regards,
> Stefan
>
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk