limited-scope retry?

Tomasz Zielonka tomasz.zielonka at gmail.com
Thu Apr 21 11:54:38 EDT 2005


On Thu, Apr 21, 2005 at 10:47:27AM -0400, Abraham Egnor wrote:
> Used in isolation, i.e.
> 
> atomically $ writeTChan chan ()
> atomically $ flush chan

> it works fine.  However, when composed (atomically $ writeTChan chan
> () >> flush chan), it causes a race condition, usually resulting in
> deadlock, as the "retry" in flush replays the call to writeTChan as
> well.

As long as you are in this transaction nobody will get from chan the
element you just put there. Before the transaction commits, for the
outside world it's like you've never called writeTChan.

But inside the transaction you see a chan with an element that you've
just written there. So within this transaction the chan has no chance to
be emptied (unless you emptied it yourself). No point in waiting.

As you say, it works in isolation. Use it this way.

Best regards
Tomasz


More information about the Glasgow-haskell-users mailing list