Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Haskell] Strange behaviour of forkIO threads

2 views
Skip to first unread message

Maurizio Monge

unread,
May 13, 2006, 5:38:00 PM5/13/06
to has...@haskell.org
Hi, i used forkIO to write a 'por' (parallel or) implementation
(just a proof of concept), arguments are evaluated in different
threads and as soon as one of the threads returns true the other
thread is killed and true is returned.
If both threads return false the result of the computation is false.

I have been doing a few tests and looks like that in some cases
the function that do not terminate (that i used to test the por
correctness) seam not be preempted, and thus the program do not
terminate.
The very strange thing is that the program (that i am attaching)
works as expected if it is compiled with -O, but hangs if compiled
without optimization!
Any idea?
Thanks

--
Ciao
Maurizio

"Well we all shine on
Like the moon and the stars and the sun" (John Lennon)

por.hs

Simon Marlow

unread,
May 15, 2006, 6:05:03 AM5/15/06
to Maurizio Monge, has...@haskell.org
Maurizio Monge wrote:
> Hi, i used forkIO to write a 'por' (parallel or) implementation
> (just a proof of concept), arguments are evaluated in different
> threads and as soon as one of the threads returns true the other
> thread is killed and true is returned.
> If both threads return false the result of the computation is false.
>
> I have been doing a few tests and looks like that in some cases
> the function that do not terminate (that i used to test the por
> correctness) seam not be preempted, and thus the program do not
> terminate.
> The very strange thing is that the program (that i am attaching)
> works as expected if it is compiled with -O, but hangs if compiled
> without optimization!

It sounds like you are just falling foul of the fact that GHC only
context switches when a thread is doing allocation; if it is sitting in
a loop not doing any allocation then you won't see a context switch. In
GHC 6.6 you'll be able to work around this to some extent by using 2
processors.

Cheers,
Simon
_______________________________________________
Haskell mailing list
Has...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell

Bulat Ziganshin

unread,
May 15, 2006, 8:52:02 AM5/15/06
to Simon Marlow, has...@haskell.org
Hello Simon,

Monday, May 15, 2006, 2:04:38 PM, you wrote:

> It sounds like you are just falling foul of the fact that GHC only
> context switches when a thread is doing allocation; if it is sitting in
> a loop not doing any allocation then you won't see a context switch. In
> GHC 6.6 you'll be able to work around this to some extent by using 2
> processors.

you want to say "2 OS threads executing Haskell program in parallel" ?
i think that 6.6 will support this mode even on single-threading
processors?

--
Best regards,
Bulat mailto:Bulat.Z...@gmail.com

Simon Marlow

unread,
May 15, 2006, 11:35:15 AM5/15/06
to Bulat Ziganshin, has...@haskell.org
Bulat Ziganshin wrote:
> Monday, May 15, 2006, 2:04:38 PM, you wrote:
>
>>It sounds like you are just falling foul of the fact that GHC only
>>context switches when a thread is doing allocation; if it is sitting in
>>a loop not doing any allocation then you won't see a context switch. In
>>GHC 6.6 you'll be able to work around this to some extent by using 2
>>processors.
>
> you want to say "2 OS threads executing Haskell program in parallel" ?
> i think that 6.6 will support this mode even on single-threading
> processors?

Yes, that's right.

Simon

0 new messages