Blocking Transactions
getR :: Resource -> Int -> STM ()
getR r i = do { v <- readTVar r
; if (v < i) then retry
else writeTVar r (v-i) }
- retry aborts the transaction, but keeps the log of memory accesses and waits until they change.
- No need for the producer to signal
- The type of retry is (STM a)
- Composability
atomic (do { getR r1 3; getR r2 7 })
- They may block but will not deadlock
- Any STM action can be robustly composed with any other STM action!