Saturday 10 January 2009

Software Transactional Memory

Software Transactional Memory is a technique that aims to simplify developing concurrent programming. It allows you to define units of work (transactions) which obey the ACID properties:

  • Atomic - work either happens completely or not at all.
  • Consistent - only valid work is carried out
  • Isolation - no-one can see intermediate work, only the final result
  • Durable - Once the work has been completed, it's done and will survive failure

During a unit of work each thread completes modifications to the (shared) data structure. All modifications are recorded in a log. When the transaction reaches the end, the memory logs are analysed; if the logs are consistent (e.g. no read/write of the same variable) then the transaction is commited, if not the transaction is aborted or retried. All functions in a transaction must be pure. IO in a transaction is wrong. A language like Haskell enforces this via its type system - IO operations are performed with a monad. STM is still very new, there's no guarantee that this will be the "winner" in the concurrency programming war...

No comments:

Post a Comment