wait(2)

Simon Marlow simonmar@microsoft.com
Thu, 26 Jul 2001 18:00:30 +0100


> Is there a way in Glasgow Haskell to get a thread to wait on=20
> a child process
> in the same way as the Posix function wait(), and get the=20
> termination status
> of the child?  If so, how?

There's a couple of ways.  The obvious way is to get the thread to place
its result in an MVar when it exits: there's a guarantee that a thread
always either exits or raises an exception, so you can wrap the
top-level computation in something that places the result/exception in
an MVar.

Alternatively, you can foreign import rts_evalIO() and do it that way.
It ought to work, but I haven't tried it.  This way lets you get at the
Interrupted or Deadlocked return states too, which you can't do solely
within Haskell.

Hmm, now I think about it, the compiler won't let you foreign import
rts_evalIO() with the type you want, namely a -> Ptr b -> IO CInt, and
quite rightly so.  You'll need a version of rts_evalIO() that takes
StablePtrs instead.

Cheers,
	Simon