|
Boost : |
From: Angus Leeming (angus.leeming_at_[hidden])
Date: 2004-06-22 16:00:03
Rob Stewart wrote:
>> I'm pretty sure that the above is safe code. It does the absolute
>> minimum in the handler routine. wait() is guaranteed to be async-safe.
>> Moreover, the handler receives only SIGCHLD signals and so cannot
>> receive multiple calls simultaneaously. However, I'm unsure whether it
>> Ok to search the map like this. Any advice?
>
> The code does very little work. The map is not likely to every
> be very large; not many applications create and track a large
> number of child processes. That means that finding the child
> will be fast; creating the map entry ahead of time saves some
> work in the signal handler, which is good.
Indeed. But primarily it should be safe, which means I should not create
new elements in whatever container I use.
[ snip alternative schemes ]
Thanks for the ideas. I'll mull them over.
>> My one other worry is that the SIGCHLD handler could be redefined
>> elsewhere in the code, but AFAICS there's nothing that I can do about
>> that. Furthermore, it means only that the user of my Child library
>> won't be able to ascertain the exit status of child processes launched
>> using it.
>
> The proper way to install a signal handler is to chain to any
> previous signal handler for the same signal. Therefore, a
> library client should write code that ensures that your handler
> gets called.
>
> You could also go the other way around. You could provide a
> mechanism for clients to install their own handler (a
> boost::function<void, int>?) for your handler to call.
Many thanks for these suggestions. That's exactly what I was looking for.
Regards,
Angus
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk