[Haskell-cafe] Implementing tryReadMVar

Einar Karttunen ekarttun at cs.helsinki.fi
Thu Sep 2 03:57:32 EDT 2004


On 01.09 18:30, MR K P SCHUPKE wrote:
> 	while channel not empty
> 		read next event
> 		if event high priority process now
> 		else queue event in FIFO
> 	process first event in FIFO

That suffers from the same problem as I described.

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. (consider a case
where we create two similar server processes reading the same
channel). Now we create a tryReadChan, but we cannot implement
it with tryTakeMVar, as that would break dupChan. Rather we
need a tryReadMVar or a different channel abstraction.

- Einar Karttunen


More information about the Haskell-Cafe mailing list