[Haskell-cafe] Re: Waiting for thread to finish

Simon Marlow simonmarhaskell at gmail.com
Mon Dec 3 08:10:50 EST 2007


Brad Clow wrote:
> On Nov 28, 2007 11:30 AM, Matthew Brecknell <haskell at brecknell.org> wrote:
>> Even with threads, results are evaluated only when they are needed (or
>> when forced by a strictness annotation). So the thread that needs a
>> result (or forces it) first will be the one to evaluate it.
> 
> So does GHC implement some sychronisation given that a mutation is
> occuring under the covers, ie. the thunk is being replaced by the
> result?

Yes, see

http://haskell.org/~simonmar/bib/multiproc05_abstract.html

we use lock-free synchronisation, with a slight possibility that two 
threads might evaluate the same thunk.  But since they'll produce the same 
result, nothing goes wrong.

Cheers,
	Simon


More information about the Haskell-Cafe mailing list