Broken beyond repair: Control.Concurrent.SampleVar

Isaac Dupree ml at isaac.cedarswampstudios.org
Sun Apr 12 17:23:20 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

withMVar is a blocking operation, thus interruptible despite 'block', I 
believe... perhaps moving the block inward might more clearly specify what 
happens (and be *at least* as correct, maybe more correct?) :

writeSampleVar s x = withMVar (svLock s) $ const $ block $ do
   tryTakeMVar (svData s)  --nonblocking, thus not exception-interruptible
   putMVar (svData s) x  --because the lock is taken and the MVar emptied,
                           -- this is guaranteed to succeed and not to block

-Isaac



More information about the Libraries mailing list