[Haskell-cafe] Broken beyond repair: Control.Concurrent.SampleVar

ChrisK haskell at list.mightyreason.com
Sun Apr 12 08:18:44 EDT 2009


Hello all,

  The SampleVar module in base is not exception safe.  I believe that there is
no way to fix this module to be exception safe while retaining the current behavior.

  The problem with the current behavior is that the writeSampleVar pretends to
know how many blocked reader threads are waiting on a value.  In reality these
blocked threads may have been killed.

  When writeSampleVar sees blocked threads it does a blocking putMVar and then
decrements the blocked reader thread count. If any two of the blocked reader
threads ever die then eventually you get a blocked writer.

  I can find no efficient way to retain the current behavior in the presence of
exceptions.  The logic of the current behavior is that the blocked readers mean
that the previously written value should not be discarded, the previous value
belongs to the next blocked reader.

  I propose that SampleVar be either removed, or replaced with a slightly
different exception safe version.  I propose not considering the previously
written value to belong to a blocked reader, and to replace it with the new value.

  I will open a ticket about this when I get more time.

-- 
Chris



More information about the Haskell-Cafe mailing list