| Prev | Next |
type Resource = TVar Int
putR :: Resource -> Int -> STM ()
putR r i = do { v <- readTVar r
; writeTVar r (v+i) }
atomic takes a memory transaction, of type STM a, and delivers an I/O action that, when performed, runs the transaction atomically with respect to all other memory transactions.
main = do { ...; atomic (putR r 3); ... }
| 26 |