Skip to content

Concurrency primitives

Category: Foundations · Status: stub

One line: The building blocks a language or library provides for concurrent code, in four groups: synchronization (mutex, semaphore, condition variable), communication (channels, futures), task management (threads, tasks, pools) and atomics.

Also called: synchronization primitives, communication primitives.

How it connects

In each language

Rust std::sync (Mutex, RwLock, Condvar, Barrier, mpsc, atomics) and std::thread
Go Channels in the language; sync, whose documentation says higher-level synchronization is better done with channels; and sync/atomic
C POSIX <pthread.h>, and C11's <threads.h> and <stdatomic.h>
C++ The concurrency support library ↗: threads, mutexes, condition variables, semaphores, futures and atomics
Java java.util.concurrent, its locks and atomic subpackages, and the monitor every object has (synchronized, wait, notify)
Python threading (Lock, Condition, Semaphore, Event, Barrier) and queue, with counterparts in asyncio
C# Overview of synchronization primitives ↗
JavaScript Workers exchange messages with postMessage; shared memory is a SharedArrayBuffer coordinated with Atomics
Kotlin Mutex and Semaphore for coroutines, which suspend rather than block; Channel
Erlang and Elixir Processes and messages; ETS ↗ is built-in term storage for very large quantities of data
Haskell MVar and Chan in base; TVar in the stm package
The operating system futex(2): a blocking construct for shared-memory synchronization, with most of the work done in user space

Where to read more