[Haskell-cafe] Data.Unique not "safe" in concurrent environments (or brain burned)?

Neil Davies semanticphilosopher at googlemail.com
Sat Sep 1 07:03:46 EDT 2007

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 mailing list