The Runtime Theory
Operating SystemsIn production

Locks and Synchronization Primitives

Recording in progress
#locks#synchronization#concurrency#mutex

A lock is a promise enforced by hardware: atomic compare-and-swap, memory barriers, and a kernel wait queue. This video shows what each primitive actually does on the machine — the atomic instruction, the cache-line contention, and the park/unpark syscall — so you can reason about why a mutex costs 20ns uncontended and a syscall-bound lock costs microseconds.

Topics covered:

  • The atomic operations that all locks are built from: CAS, fetch-add, barriers
  • Spinlocks: spinning on a cache line and why they're only for short critical sections
  • Mutexes: the uncontended fast path vs. the contended futex slow path
  • Semaphores and counting: producer/consumer signaling, not just mutual exclusion
  • Condition variables: why wait() must atomically release the mutex
  • Reader-writer locks and the writer-starvation problem
  • Lock-free programming: when CAS-based retry loops beat locks
  • The cost model: contention, cache-line bouncing, and false sharing

Related articles

More in Operating Systems

19:20
operating systems

Virtual Memory in One Diagram

Page tables, TLB, demand paging, and copy-on-write — how your 16GB laptop 'has' 128GB of addressable memory.

Watch
In production
operating systems

Container Isolation in Linux

What Docker and Kubernetes containers actually are — namespaces, cgroups, and the syscalls that make isolated processes without a VM.

Details
In production
operating systems

Signals and Interrupts

Hardware interrupts and Unix signals — the two asynchronous mechanisms that interrupt your program, and what the kernel does between the wire and your handler.

Details
In production
operating systems

Memory-Mapped Files

How mmap() maps a file into your address space — demand paging from disk, the page cache, and why mapped I/O beats read() and write().

Details
In production
operating systems

File Systems Explained

How a file system stores your data — inodes, directory entries, extents, and journaling — and what actually happens on read and write.

Details
In production
operating systems

Thread Pools Explained

How thread pools work under the hood — worker threads, work queues, and why reusing threads beats spawning them for every request.

Details
In production
operating systems

Syscalls Under the Hood

What actually happens when your program calls read(), open(), or fork() — the trap, the kernel mode switch, and the return path.

Details
In production
operating systems

Virtual Memory Explained

Address translation, page tables, and the TLB — the full path from a virtual address to the physical RAM cell, including why the translation is cached.

Details
In production
operating systems

Process Scheduling, Visualized

How the Linux scheduler picks the next runnable process — time slices, priorities, CFS virtual runtime, and why your busy server still feels responsive.

Details

Depth, delivered weekly

One technical dispatch a week — articles and episode notes before they go public.

One technical dispatch per week. No noise.