Concurrent programming techniques, pros, cons

Viewed 3727

There is at least three well-known approaches for creating concurrent applications:

  1. Multithreading and memory synchronization through locking(.NET, Java). Software Transactional Memory (link text) is another approach to synchronization.

  2. Asynchronous message passing (Erlang).

I would like to learn if there are other approaches and discuss various pros and cons of these approaches applied to large distributed applications. My main focus is on simplifying life of the programmer.

For example, in my opinion, using multiple threads is easy when there is no dependencies between them, which is pretty rare. In all other cases thread synchronization code becomes quite cumbersome and hard to debug and reason about.

4 Answers

In Erlang and OTP in Action, the authors present four process communication paradigms:

  • Shared memory with locks

    A construct (lock) is used to restrict access to shared resources. Hardware support is often required from the memory system, in terms of special instructions. Among the possible drawbacks of this approach: overhead, points of contention in the memory system, debug difficulty, especially with huge number of processes.

  • Software Transactional Memory

    Memory is treated as a database, where transactions decide what to write and when. The main problem here is represented by the possible contentions and by the number of failed transaction attempts.

  • Futures, promises and similar

    The basic idea is that a future is a result of a computation that has been outsourced to a different process (potentially on a different CPU or machine) and that can be passed around like any other object. In case of network failures problem can arise.

  • Message passing

    Synchronous or asynchronous, in Erlang style.

Related