Skip to main content
The 2024 Developer Survey results are live! See the results

In computer science, concurrency is a property of systems in which multiple computations can be performed in overlapping time periods. The computations may be executing on multiple cores in the same chip, preemptively time-shared threads on the same processor, or executed on physically separated processors.

Concurrency is a property of systems in which several computations can be in progress simultaneously, and potentially interacting with each other. The computations may be executing on multiple cores in the same chip, preemptively time-shared threads on the same processor, or executed on physically separated processors.

A number of mathematical models have been developed for general concurrent computation including Petri nets, process calculi, the Parallel Random Access Machine model, the Actor model and the Reo Coordination Language.

Issues

Because computations in a concurrent system can interact with each other while they are executing, the number of possible execution paths in the system can be extremely large, and the resulting outcome can be indeterminate. Concurrent use of shared resources can be a source of indeterminacy leading to issues such as deadlock, and starvation.

Performance

A common misconception is that increasing concurrency will always improve performance. While it can improve throughput for CPU bound processes by using more CPUs, and I/O bound tasks by amortising the latency of each task, there is many situation where more concurrency hurts performance. Even when it improves performance it can reduce maintainability.

Examples of where concurrency doesn't help

  • The overhead of using multiple threads, exceeds the potential improvement. e.g. You have a very short task, but it takes a long time to pass it (and the data associated with it) to another thread.
    • e.g. the cost of locking a resource exceeds the time taken in the protected operation. A single threaded task might perform much better (and be simpler)
  • You are already using a shared resource to it's maximum extent. e.g. all your CPUs, hard drives, network connection are fully utilised. In this case, the overhead can increase decreasing overall performance.
  • You don't need a performance increase, but adding concurrency increases the complexity of your application. A common argument is; you have to use all your CPUs because they are there (even if there is nothing to gain and everything to lose)

References