
26 Jan
2012
26 Jan
'12
9:58 p.m.
On 1/23/12 3:19 PM, Edward Z. Yang wrote:
Excerpts from Heka Treep's message of Mon Jan 23 15:11:51 -0500 2012:
actor mbox = do empty<- atomically $ isEmptyTChan mbox if empty then actor mbox else do val<- atomically $ readTChan mbox
Uh, don't you want to combine isEmptyChan and readTChan into one single atomic action?
Why are you writing a busy loop? STM is designed such that if you have a single transaction that tries to read from an empty TChan then that thread will be put to sleep and awakened only once there's some activity on that TChan. Using STM is not the same as lock-based code; you shouldn't treat it like it is. -- Live well, ~wren