Concurrent Haskell problem/bug

Greg Mildenhall
Tue, 10 Jul 2001 04:14:25 +0800 (WST)

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:
PPM: no threads to run:  infinite loop or deadlock?

So there _does_ seem to be a strange interaction between seperate
occurrences of ppm'. Can anyone see how that is happening?
(of course the other possibility is that I've done something
really silly in my code and not noticed, but I'm happy to take
suggestions on that front, too. :)

If noone here can see what is causing it, is anyone here brave enough
to say "this is probably a GHC bug" and recommend how best I report it?

Thanks for any insight you can offer me.

-Greg Mildenhall