Software Transactional Memory

Software Transactional Memory (STM) is the highest-level general concurrency abstraction we will consider. STM provides composable atomic transactions, meaning we can combine reads, writes, and other operations in multiple memory locations into single atomic operations. Transactions can be aborted or retried.

An STM transaction lives in the STM monad:

data STM a
instance Monad STM

Transactions are performed with the atomically function:

atomically :: STM a → IO a

Another important primitive is the retry function, which aborts the current transaction and retries it when some of its dependencies have changed (in some other transaction in another thread):

retry :: STM a

Basic transactional variables are provided by the STM ...

Get Haskell High Performance Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.