SampleVar semantics

Eric Stansifer eric.stansifer+haskell at gmail.com
Sun Jan 2 22:42:25 CET 2011


Unfortunately this code can deadlock.

Consider

main = do
    svar <- newEmptySampleVar
    forkIO $ readSampleVar svar
    threadDelay 1000000
    forkIO $ writeSampleVar svar ()
    threadDelay 1000000
    emptySampleVar svar

This program deadlocks, but emptySampleVar should return immediately.
After writeSampleVar is executed, the SampleVar thinks the val is
full, so emptySampleVar tries to empty it, entering a deadlock.

Eric



More information about the Libraries mailing list