|
Boost : |
From: Jonathan Biggar (jon_at_[hidden])
Date: 2004-06-22 17:26:48
Angus Leeming wrote:
> namespace {
>
> std::map<pid_t, int> completed_children;
>
> int status;
> sig_atomic_t pid;
>
> }
>
> 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 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?
That's not safe code, since the child_handler() function could be called
at any time, interrupting other code that is modifying the
completed_children map.
-- Jon Biggar Floorboard Software jon_at_[hidden] jon_at_[hidden]
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk