How does forkIO and par interact?

Simon Marlow marlowsd at gmail.com
Mon Dec 21 07:34:06 EST 2009


On 20/12/2009 14:12, Marcus D. Gabriel wrote:
> Thanks Bulat.  What you wrote makes perfect sense to me.  However under
> 6.10.4
> this is what I observed.  Pseudo code:
>
>      c = l++r `demanding` l>||r
>
> then
>
>      th<- forkIO (c `seq` return ())
>
> Run it the first time to completion and watch two cores turn at better
> than 95% utilisation, quite pleasing.  Run it the second time and half
> way through the calculation use
>
>      killThread th
>
> and watch one core become idle and one core turn at better than 95%.
> Wait until the first core finishes and then use c and watch the rest
> of the calculation finish.
>
> Now, what you wrote and this experiment tells me that l was sparked
> and then given a free thread in which to calculate.  r was still in the
> original thread of execution of the forkIO and therefore was affected by
> the killThread th whereas l was not.
>
> Does this read correct to you?  If so, then I understand!

That's exactly right, yes.

In principle we could have spark threads be garbage collected if their 
results aren't shared by the main program.  In practice that's hard to 
determine, since sharing is not an all-or-nothing question.  There's a 
fruitful line of research here, though, since it affects how well you 
can express speculation.

Cheers,
	Simon


More information about the Glasgow-haskell-users mailing list