[Haskell-cafe] Re: Data.Unique not "safe" in concurrent
environments (or brain burned)?
semanticphilosopher at googlemail.com
Sat Sep 1 07:13:07 EDT 2007
Let me answer this myself - brain burnt...
Of course it is OK, that is precisely the semantics of MVars - the are
empty or full, thus assuring the mutual exclusion between threads.
Been a hard week.....
... so the deeper question - why don't you realise these mistakes till
five minutes *after* you've pressed the send button....
Neil Davies wrote:
> Hi, I was looking over the libraries for bits of GHC (no doubt a standard form of
> relaxation for readers of this list), and noticed the following statement
> (in Data.Unique):
> -- | Creates a new object of type 'Unique'. The value returned will
> -- not compare equal to any other value of type 'Unique' returned by
> -- previous calls to 'newUnique'.
> This set me thinking - so I looked at the code
> newUnique :: IO Unique
> newUnique = do
> val <- takeMVar uniqSource
> let next = val+1
> putMVar uniqSource next
> return (Unique next)
> In the concurrent execution world in which we live - I don't think that the implementation
> supports the "uniqueness" statement above - or am I not understanding something?
More information about the Haskell-Cafe