multiple processes and threads

Simon Marlow
Tue, 26 Feb 2002 12:41:41 -0000

> I have an application that uses multiple processes and=20
> multiple threads
> together.  What's the best way to detect child process terminations?
> The initial thread in the inital process serves as driver of the
> application.  It creates child processes and threads to carry out
> portions of the computation.  A natural way to have the driver detect
> termination of these child processes and threads would be to have the
> driver "listen" on a single MVar to which termination notices are
> "posted".  Child threads would simply post their termination notices
> directly.  For child processes, I'd like to have a single=20
> thread in the
> initial process execute (getAnyProcessStatus True False) repeatedly,
> posting a termination notice each time such a call returns.  However,
> with the current implementation of Concurrent Haskell, when the thread
> pends on the getAnyProcessStatus call, the entire initial process
> pends.  The best solution I've come up with so far, which is
> unsatisfying, is to have this thread poll periodically (that is, loop
> over (getAnyProcessStatus False False) and (threadDelay)).  Is there a
> better way?

One (possibly better) way is to listen for SIGCLD.  This has been =
discussed a couple of times before, threads here:

The upshot is the GHC *should* provide a better mechanism than it does =
currently, but it doesn't, sorry :-)