
27 May
2009
27 May
'09
2:59 p.m.
I wrote:
Krzysztof Skrzętnicki wrote:
The code for modifying the counter: (\ msg -> atomicModifyIORef ioref (\ cnt -> (cntMsg cnt msg,())))
atomicModifyIORef does not force the new value of the IORef. If the previous contents of the IORef is x, the new contents will be a thunk,
(\ cnt -> (cntMsg cnt msg,())) x
Sorry, it's slightly worse than that. The contents becomes sel_0 (\ cnt -> (cntMsg cnt msg, ())) x where sel_0 is basically an RTS internal version of fst. Instead of reading the new value of the IORef, you could also force the old one: atomicModifyIORef ioref (\ cnt -> (cntMsg cnt msg, msg)) >>= (return $!) Bertram