Concurrency

Concurrency

Virtual threads, async/await, work-stealing, lock contention, memory models.

62Articles
62Topics covered
Articles in this category

All 52 articles, sorted alphabetically

ARTICLE · 01

Actor Pattern Explained, in depth: Akka Typed interaction patterns and the threads underneath, from request-response to pipeToSelf, stash, aggregators and work pulling

The actor pattern from a threading point of view, with Akka Typed code: how dispatchers run many actors on few threads, request-response with replyTo,…

Read article →
ARTICLE · 02

Async/Await Patterns, in depth: fan-out, bounded concurrency, timeouts and cancellation

The async/await patterns that hold up under load: how await suspends a task, concurrent fan-out with TaskGroup, bounded concurrency with semaphores, d…

Read article →
ARTICLE · 03

Coroutines vs Threads Architecture (Kotlin / Go / Rust), in depth

Kotlin coroutines, Go goroutines and Rust async tasks compared as architectures: one fan-out program in all three, where paused state lives, who sched…

Read article →
ARTICLE · 04

Java Executor Framework Architecture, in depth

Inside Java's Executor framework: interface layering, ThreadPoolExecutor's ctl word and workers, FutureTask states, the scheduled pool'…

Read article →
ARTICLE · 05

Goroutines at Scale, in depth: the scheduler, stack costs, container GOMAXPROCS, bounding fan-out and finding leaks

How Go runs very large numbers of goroutines and how to keep them under control: G, M and P, run queues and work stealing, the netpoller and preemptio…

Read article →
ARTICLE · 06

Green Threads, in depth: the M:N model, why it lost and came back, and a runtime you can build in 70 lines of C

Green threads explained from first principles: 1:1, N:1 and M:N threading, the history from Java 1.1 and NPTL to Go, Erlang and Java virtual threads, …

Read article →
ARTICLE · 07

Java Virtual Threads in Production, in depth: a runbook with the version matrix, telemetry to wire first, a canary plan and six incidents with their fixes

A production runbook for Java virtual threads: which JDK to run, JFR streaming, the scheduler MXBean and JSON thread dumps wired up before the switch,…

Read article →
ARTICLE · 08

Java Virtual Threads Pitfalls, in depth: code-level traps with reproducers, detection and fixes

The code-level pitfalls of Java virtual threads, each with a reproducer and a fix: pooling virtual threads, CompletableFuture and parallel streams esc…

Read article →
ARTICLE · 09

Lock Contention Diagnosis, in depth: symptoms, queueing arithmetic, contention profilers for Linux, Java and Go, worked fixes and a checklist

A repeatable method for diagnosing lock contention: recognising the signature and its impostors, lock utilisation and wait-time arithmetic, a triage w…

Read article →
ARTICLE · 10

Lock-Free Data Structures, in depth: when they beat locks, three correct builds, and how to test them

A practical guide to lock-free data structures: progress guarantees, when a mutex is the better choice, atomics and memory ordering, worked C++ builds…

Read article →
ARTICLE · 11

Producer/Consumer Architecture with BlockingQueue, in depth

Producer/consumer with Java BlockingQueue in depth: the four method families, ArrayBlockingQueue versus LinkedBlockingQueue locking, SynchronousQueue …

Read article →
ARTICLE · 12

Reactive Streams Backpressure Architecture

How reactive streams (Project Reactor, RxJava) propagate demand upstream — the Publisher contract, request(N), TCK semantics, overflow strategies, and…

Read article →
ARTICLE · 13

The Rust Async Runtime Picture, in depth: futures, wakers, the reactor, Tokio's work-stealing scheduler, cooperative budgets and blocking pools

A complete mental model of async Rust at runtime: the Future trait and its state machines, a minimal block_on executor, wakers and the epoll/kqueue/IO…

Read article →
ARTICLE · 14

Actor Model, in depth: the semantics of send, create and become, what the model leaves unguaranteed, and how Erlang and Akka narrow it

The actor model as semantics rather than a library: the send, create and become axioms, what the pure model does not promise (ordering, bounded delay,…

Read article →
ARTICLE · 15

Atomic Operations, in depth: read-modify-write instructions, CAS loops, what the hardware does, and the price of contention

Atomic operations from first principles: why counter++ loses updates, the read-modify-write set across C++, Java, Rust and Go, how x86 LOCK and ARM LL…

Read article →
ARTICLE · 16

Coroutines, in depth: how suspension is implemented, stackless state machines versus stackful stacks, a scheduler built from generators, and the bugs each design invites

How coroutines actually work: the state a suspension must save, how compilers lower async functions into state machines in Python, Rust, C++20, C# and…

Read article →
ARTICLE · 17

Deadlock, in depth: the shapes it takes in real code, reading thread dumps in Java, Python and Go, the deadlocks detectors miss, and fixing one end to end

A practical guide to deadlock: the resource-graph model, seven shapes deadlock takes in production code, a worked transfer bug with its thread dump an…

Read article →
ARTICLE · 18

Futures and Promises, in depth: building one from scratch, how Java, C++, JavaScript, Python and Rust differ, and the bugs each invites

Futures and promises explained by building a thread-safe promise in Python, then comparing Java CompletableFuture, C++ std::promise and std::future, J…

Read article →
ARTICLE · 19

Thread Lifecycle, in depth: Java thread states, Linux task states, birth, waiting, death and reading a stuck process

The real thread lifecycle: the six Java Thread.State values and what moves a thread between them, why RUNNABLE includes blocking I/O and ReentrantLock…

Read article →
ARTICLE · 20

Locks and Mutexes, in depth: exclusion and visibility, futexes, fairness, lock design and contention

How mutexes really work and how to use them well: the exclusion and visibility guarantees, a futex-based three-state mutex, adaptive spinning, fairnes…

Read article →
ARTICLE · 21

Thread Pools, in depth: admission order, sizing with Little's law, queue choice, starvation deadlock and the metrics that show saturation

How thread pools really behave: the ThreadPoolExecutor admission order (core, queue, max, reject), why an unbounded queue silently disables maximumPoo…

Read article →
ARTICLE · 22

Race Conditions, in depth: data races vs race conditions, the five shapes, deterministic reproduction and detection tools

A practical guide to race conditions: the difference between data races and race conditions, read-modify-write, check-then-act, TOCTOU, unsafe publica…

Read article →
ARTICLE · 23

Thread Synchronization, in depth: exclusion, ordering, happens-before and choosing the right primitive

How thread synchronization works: the two jobs of exclusion and visibility, happens-before as the rule under every primitive, a decision procedure for…

Read article →
ARTICLE · 24

Actor model architecture, in depth: mailboxes, dispatchers, supervision, backpressure and a runtime you can read

How actor runtimes work and how to operate them: actor refs, bounded mailboxes and overflow policies, dispatchers that share threads fairly, a runnabl…

Read article →
ARTICLE · 25

Actor Model Architecture in Depth

Actor model architecture for real systems: actor granularity, supervision trees, cluster sharding, virtual actors, event-sourced persistence, delivery…

Read article →
ARTICLE · 26

Thread barrier architecture

Deep-dive on thread barriers: the party count and arrival protocol, the last-arriver that trips the barrier, the run-once barrier action, the generati…

Read article →
ARTICLE · 27

Channels Architecture, in depth: capacity, close and select semantics, Go runtime internals, and channels in Kotlin, Rust and Java

Channels as a concurrency primitive: what a channel combines, the design choices of capacity, multiplicity, close and select, how the Go runtime imple…

Read article →
ARTICLE · 28

Condition Variable Architecture, in depth: the mutex-predicate-queue triple, Mesa semantics, lost wakeups, signal vs broadcast and how it is built

How condition variables work and how to use them correctly: why a condition variable needs a mutex and a predicate, the canonical wait loop in Java, C…

Read article →
ARTICLE · 29

Coroutines -- cooperative suspension for concurrency

Deep-dive on coroutines: functions that suspend at await/yield points, cooperative scheduling, the event loop, cheap massive IO-bound concurrency vs t…

Read article →
ARTICLE · 30

Deadlock detection and prevention architecture - Coffman conditions, lock ordering, recovery

Deep-dive on deadlock: the four Coffman conditions and the wait-for graph, prevention via lock ordering, avoidance with the Banker's algorithm, d…

Read article →
ARTICLE · 31

LMAX Disruptor architecture, in depth: the ring buffer, sequences and barriers, claim and publish, wait strategies, and consumer graphs

How the LMAX Disruptor passes messages between threads without locks: the pre-allocated power-of-two ring buffer, sequence counters and gating, the si…

Read article →
ARTICLE · 32

False sharing architecture

Deep-dive on false sharing: how a 64-byte cache line and the MESI coherence protocol turn independent per-thread writes into an invalidation storm, wh…

Read article →
ARTICLE · 33

ForkJoinPool architecture, in depth: the queue array, idle-worker signalling, what join() really does, compensation and how to read a stuck pool

Inside Java's ForkJoinPool: external submission queues versus worker-owned deques, the ctl word and how idle workers are woken, what join() does …

Read article →
ARTICLE · 34

Futures and promises architecture

Deep-dive on futures and promises: the shared write-once state cell, promise as the write end and future as the read end, the callback-registration ra…

Read article →
ARTICLE · 35

Hazard pointers architecture

Deep-dive on hazard pointers, the safe-memory-reclamation scheme that lets lock-free stacks, queues, and maps free deleted nodes without use-after-fre…

Read article →
ARTICLE · 36

Lock-Free Data Structures Architecture in Depth

How lock-free data structures really work: progress guarantees, CAS and cache coherence, memory ordering, the Treiber stack, the Michael-Scott queue, …

Read article →
ARTICLE · 37

Java Memory Model architecture

Deep-dive on the JMM as a system: compiler and CPU reordering, store buffers vs cache coherence, happens-before edges from volatile, monitors, final f…

Read article →
ARTICLE · 38

Priority inversion architecture

Deep-dive on priority inversion: the three-thread scenario that rebooted Mars Pathfinder, bounded vs unbounded inversion, priority inheritance and cei…

Read article →
ARTICLE · 39

Read-Copy-Update (RCU) architecture

Deep-dive on RCU: near-free lock-free reads via rcu_read_lock and rcu_dereference, the writer's copy-swap-publish protocol with rcu_assign_pointe…

Read article →
ARTICLE · 40

Read-write lock architecture

Deep-dive on read-write (shared-exclusive) locks: reader-count/writer-flag internals, readers- vs writer-preference fairness and starvation, the upgra…

Read article →
ARTICLE · 41

Thread Scheduler Architecture in Depth

A 2500-word walkthrough of thread scheduler: CFS/EEVDF, priority + niceness, work stealing, preemption, real-time, cgroups, NUMA, affinity.

Read article →
ARTICLE · 42

Semaphore architecture

Deep-dive on counting semaphores: the atomic permit count and wait queue, acquire/release on a queued synchronizer, fair vs non-fair (barging) acquisi…

Read article →
ARTICLE · 43

Seqlock architecture

Deep-dive on the seqlock: the even/odd sequence counter, optimistic reader retry, the exact acquire/release memory ordering that makes it correct, wri…

Read article →
ARTICLE · 44

Spinlock architecture

Deep-dive on spinlocks: the spin-versus-sleep decision governed by hold time and core count, compare-and-swap with acquire/release barriers, cache-lin…

Read article →
ARTICLE · 45

Structured concurrency architecture

Deep-dive on structured concurrency: scope lifecycles and the join guarantee, fail-fast vs first-success vs collect-all policies, cooperative cancella…

Read article →
ARTICLE · 46

ThreadLocal Architecture, in depth: inside ThreadLocalMap, the native TLS underneath, and carrying per-thread context across pools, async code and other runtimes

How per-thread storage is built: the three possible designs, Java's ThreadLocalMap with its golden-ratio hash, linear probing, weak keys and lazy…

Read article →
ARTICLE · 47

Thread pools -- reuse threads instead of creating them

Deep-dive on thread pools: the thread-per-task cost problem, reusable worker threads, the task queue, bounded concurrency, pool sizing (CPU-bound vs I…

Read article →
ARTICLE · 48

JVM virtual threads architecture, in depth: the runtime traced from start() to unmount, stack chunks, the scheduler, and capacity once threads are free

How JVM virtual threads actually run: the park-freeze-unmount-thaw cycle, heap stack chunks and their GC cost, the FIFO ForkJoinPool scheduler and com…

Read article →
ARTICLE · 49

Work-stealing schedulers

Deep-dive on work-stealing schedulers: per-thread deques, LIFO-local/FIFO-steal mechanics, fork-join pairing and locality, low contention, blocking ha…

Read article →
ARTICLE · 50

ThreadLocal vs ScopedValue Architecture

How to carry request-scoped data across threads in Java, why ThreadLocal breaks under virtual threads, and when ScopedValue is the right choice. Memor…

Read article →
ARTICLE · 51

Virtual Threads vs Platform Threads: Two Architectures Behind One API

Virtual threads versus platform threads in Java, compared in depth: 1:1 OS threads versus continuations on carriers, memory and switching costs, block…

Read article →
ARTICLE · 52

Work-Stealing Scheduler Architecture

The scheduler pattern behind Fork/Join, Go's runtime, and Rust's Tokio. How per-worker queues, LIFO/FIFO dual-end stealing, and cache-friend…

Read article →