[Haskell-cafe] Implementing tryReadMVar

MR K P SCHUPKE k.schupke at imperial.ac.uk
Thu Sep 2 07:53:17 EDT 2004

>do e <- isEmptyChan ch -- is the channel empty?
>   case e of
>    True -> processFifo
>    False-> readChan ch >>= highPriorityOrPush

>Now there is danger of blocking on the readChan.

Erm, but it does not matter if the readChan blocks... This is
specifically for the case where there is multiple threads writing
and one reading... 

With multiple reading threads... well it depends on the plumbing, you
could have one channel per reading thread, or one channel with a single
thread looking ahead for high priority events, and then instead of a
FIFO, another channel going to the worker threads that just read

do e <- readChan ch
if e highPriority then process e else writeChan ch2 e


More information about the Haskell-Cafe mailing list