Broken beyond repair: Control.Concurrent.SampleVar

Chris Kuklewicz haskell at list.mightyreason.com
Sun Apr 12 12:12:15 EDT 2009


Felipe Lessa wrote:
>> writeSampleVar :: SampleVar a -> a -> IO ()
>> writeSampleVar s x = block $ withMVar (svLock s) $ const $ do
>>   tryTakeMVar (svData s)
>>   putMVar (svData s) x

That is obvious, but 'block $' is not atomic.

Threads 1 and 2 get past the tryTakeMVar.

Then thread 1 succeeds with putMVar and thread 2 blocks.

Thread 2 is not supposed to block, so this is a failure to agree with the
specification.



More information about the Libraries mailing list