How does forkIO and par interact?

Marcus D. Gabriel marcus at
Sun Dec 20 08:17:26 EST 2009


How does forkIO (forkOS) and par interact with one another?  Here is
why I ask.

I have a GUI application that has something like this:

    th <- forkIO (guiCode + longRunningPureSerialCode)

Later, a user interaction invokes

    killThread th

and the guiCode plus the longRunningPureSerialCode suspends quite
nicely.  Now I have

    th <- forkIO (guiCode + longRunningPureParallelCode)

Later a user interaction invokes killThread th again but I have
observed under 6.10.4 that not all is suspended.  From what I have
observed, I believe that if

    longRunningPureParallelCode = ... 1stPart `par` 2ndPart ...

the 2ndPart is suspended by killThread th along with the guiCode, and
the 1stPart happily continues calcualting.  (I believe this is correct
but it could be the other way around.)

For my little application, having everything suspend would have been
nice, but that's my app.

So, under ghc, how is forkIO (forkOS) and par supposed to operationally
interact with one another?

- Marcus

More information about the Glasgow-haskell-users mailing list