How does forkIO and par interact?
Marcus D. Gabriel
marcus at gabriel.name
Sun Dec 20 09:12:03 EST 2009
Thanks Bulat. What you wrote makes perfect sense to me. However under
this is what I observed. Pseudo code:
c = l++r `demanding` l>||r
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
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!
Bulat Ziganshin wrote:
> Hello Marcus,
> Sunday, December 20, 2009, 4:17:26 PM, you wrote:
> par adds so-called spark to the queue of calculations to proceed. once
> RTS has free thread, this thread starts to calculate the spark. it has
> no communication with thread that created the spark. when calculation
> is completed, its thunk will be updated with result of calculation (as
> usual in lazy calculations). so killing originator thread doesn't
> affect all the sparks it has created, it only prevents generation of
> new sparks.
Marcus D. Gabriel, Ph.D. Saint Louis, FRANCE
http://www.marcus.gabriel.name mailto:marcus at gabriel.name
Tel: +22.214.171.124.05.06 Portable: +126.96.36.199.07.75
More information about the Glasgow-haskell-users