Asynchronous exceptions and laziness bugs in Data.Unique.newUnique

Simon Marlow marlowsd at gmail.com
Fri Mar 19 09:53:30 EDT 2010


On 19/03/2010 13:16, Bas van Dijk wrote:
> On Thu, Mar 18, 2010 at 11:45 AM, Simon Marlow<marlowsd at gmail.com>  wrote:
>> Thanks, I'm actually going to change this to use STM as it does a better job
>> than MVars in this case.
>
> Hi Simon, I see you actually write 'val+1' to the MVar:
>
> newUnique :: IO Unique
> newUnique = atomically $ do
>    val<- readTVar uniqSource
>    let next = val+1
>    writeTVar uniqSource $! val + 1
>    return (Unique next)
>
> Why don't you write 'next' so that when you force the returned Unique
> it doesn't need to be computed a second time?
>
> (The attached patch fixes it)

Yes, silly mistake.  I'll apply your patch, thanks.

Cheers,
	Simon



More information about the Libraries mailing list