STM blocking (via retry
) behaves as if it retries the transaction immediately, but the implementation is smarter: Since STM keeps track of what variables you've read as the transaction goes on, it knows that the transaction will behave the same way as long as those variables have the same values. So when a transaction fails, it'll block (won't actually retry) until one of the variables you used has changed. In the case of TChan
s, that means it'll block until someone writes to the TChan
.
I recommend Simon Marlow's slides on concurrent and parallel Haskell for a good introduction to STM (among other things).