On Mon, Aug 23, 1999 at 11:30:47 +0200, George Russell wrote:
> Michael Weber <[EMAIL PROTECTED]> wrote
> [snip]
> > forkChild :: IO () -> IO (MVar ())
> > forkChild p = do
> > mvar <- newEmptyMVar
> > forkIO (p >> putMVar mvar ())
> > return mvar
> This does not of course synthesise a non-daemonic forkIO from a daemonic one, because
> it requires the parent thread to wait for the MVar. I suppose that a possible
>alternative
> to having separate daemonic and non-daemonic forking would be to have an atexit-type
> function:
> atThreadExit :: IO () -> IO()
> which forkChild could use to wait for the mvar. But I'm not sure I like this, unless
> there are other likely uses for atThreadExit.
You're right. With the above code, the parent chooses, for which children it
has to wait (like this is done with Un*x fork() syscalls).
If I get it right, you want a forked process to be able to shutdown the
whole system?
\begin{code}
import Concurrent( forkIO, yield )
import System ( exitWith, ExitCode(ExitSuccess) )
import Monad ( mapM_ )
main :: IO ()
main = do
forkIO (forever $ putChar 'a')
forkIO (mapM_ putChar (replicate 10000 'b') >> exitWith ExitSuccess)
forever $ return ()
where
forever :: IO a -> IO a
forever p = p >> yield >> forever p
\end{code}
Cheers,
Michael
--
* Chemical Engineering is like looking for a black cat in a dark room.
* Software Engineering is like looking for a black cat in a dark room in
which there is no cat.