Overview

Very often, the possibility of deadlock is seen as an inherent problem of concurrent programming. This is wrong. Deadlock is a problem of one type of approach to concurrency, or category of approches, that of lock based ones. But there exist other models of concurrency, like Software Transactional Memory (STM), where deadlock doesn't exist, because there are simply no locks.

LibCMT is a library implementing the ideas given on Simon Peyton Jones et al's paper "Composable Memory Transactions", which uses a STM model where transactions has the possibility to be composed together.

The two distinctive characteristics of this approach to concurrency are:

  • There is no deadlock.
  • Transactions are composable.

Being composable means that if two transactions are correct (from the point of view of concurrency), they can be glued together to form another transaction, and this transaction is correct (from the point of view of concurrency) without extra effort. On the LibCMT's model this is true even on the presence of blocking transactions.

There are two types of composition available: by sequence and by 'orElse' alternative (where the second transaction is run if the first blocks, allowing to wait for many things at once). Any number of transactions can be composed on any order, and any of them can block, and the model guarantees there is no deadlock nor livelock nor priority inversion.

Until now, there has been some  implementations of STM available, but there wasn't any ready to use C library providing composable memory transactions (see Related Work).