Concurrent Haskell problem/bug
Greg Mildenhall <assassin <at> live.wasp.net.au>
2001-07-09 20:14:25 GMT
I posted this on comp.lang.functional and someone suggested I try here.
Apologies if it's not on-charter here - any redirections appreciated.
I'm seeing unexpected behaviour from GHC 5. (unexpected by me, anyway :)
The code which is producing the surprising results is at the bottom, but
I'll breifly explain how it is meant to work here:
ppm' spawns three threads, and hands them all an MVar.
Each thread just puts a True into that MVar and exits.
ppm' takes three values in turn from the MVar and makes sure they are all
True - if it sees a False value, it stops looking. Once it has assessed
whether they have all returned true, it kills all of its child threads
before returning the result of the assessment.
In this case, where each child returns True, the threads will have already
exited, but my understanding is that they are not GCed while ppm' has a
reference to their ThreadIds, so ppm' is still allowed to kill them.
The ppm' function is "done" 11 times (but some slightly modified versions
caused me to need up to a hundred invocations in order to see the problem,
so if you don't see the problem on your GHC, try > 11) and each invocation
is wrapped up in an unsafePerformIO. (I don't think the unsafePerformIO
should be a problem, because there oughtn't be any interaction between the
seperate ppm' instances.)
Some of these 11 seem to return the expected result, but one of them
doesn't. The output is this: