Software Transactional Memory - Conceptual Advantages and Disadvantages

Conceptual Advantages and Disadvantages

In addition to their performance benefits, STM greatly simplifies conceptual understanding of multithreaded programs and helps make programs more maintainable by working in harmony with existing high-level abstractions such as objects and modules. Lock-based programming has a number of well-known problems that frequently arise in practice:

  • It requires thinking about overlapping operations and partial operations in distantly separated and seemingly unrelated sections of code, a task which is very difficult and error-prone.
  • It requires programmers to adopt a locking policy to prevent deadlock, livelock, and other failures to make progress. Such policies are often informally enforced and fallible, and when these issues arise they are insidiously difficult to reproduce and debug.
  • It can lead to priority inversion, a phenomenon where a high-priority thread is forced to wait for a low-priority thread holding exclusive access to a resource that it needs.

In contrast, the concept of a memory transaction is much simpler, because each transaction can be viewed in isolation as a single-threaded computation. Deadlock and livelock are either prevented entirely or handled by an external transaction manager; the programmer needs hardly worry about it. Priority inversion can still be an issue, but high-priority transactions can abort conflicting lower priority transactions that have not already committed.

On the other hand, the need to abort failed transactions also places limitations on the behavior of transactions: they cannot perform any operation that cannot be undone, including most I/O. Such limitations are typically overcome in practice by creating buffers that queue up the irreversible operations and perform them at a later time outside of any transaction. In Haskell, this limitation is enforced at compile time by the type system.

Read more about this topic:  Software Transactional Memory

Famous quotes containing the words conceptual and/or advantages:

    I thought it was a wonderfully conceptual act actually, to fire a replica pistol at a figurehead—the guy could have been working for Andy Warhol!
    —J.G. (James Graham)

    In 1845 he built himself a small framed house on the shores of Walden Pond, and lived there two years alone, a life of labor and study. This action was quite native and fit for him. No one who knew him would tax him with affectation. He was more unlike his neighbors in his thought than in his action. As soon as he had exhausted himself that advantages of his solitude, he abandoned it.
    Ralph Waldo Emerson (1803–1882)