[Haskell-cafe] Number of outstanding messages in Chan or TChan
Bulat Ziganshin
bulatz at HotPOP.com
Tue Dec 6 08:47:33 EST 2005
Hello Joel,
Tuesday, December 06, 2005, 12:54:57 PM, you wrote:
JR> Is there a way to check the number of outstanding messages in a Chan
JR> or TChan?
either
1) use MVars/TMVars instead of Channels. in any case your logging
thread must consume data not slower than other channels produce then.
in fact, using Chan have meaning only to smooth temporary speed
differences between different threads. are you really need this??
2) i hope that you already replaced passing a Chan to subroutines with
passing an actions that read/write this Chan. in this case you can go
further and add to this actions incrementing/decrementing MVar
counter. but even without tests it's evident that 1000 producer threads
will get 1000 times more attention than 1 consumer thread if you don't
have any restrictions on producing and consuming data. if you
absolutely don't want to use MVars instead of channels, then at least you
can modify these actions so that number of Chan elements will be
limited (use additional "MVar full" which is filled in case of too
large number of elements in channel and emptied by logger thread)
--
Best regards,
Bulat mailto:bulatz at HotPOP.com
More information about the Haskell-Cafe
mailing list