Skip to content

โšก Concurrency, Parallelism & Scheduling

Threads, locks, async, schedulers the hardest problems in computing after naming things.

โ†’ See also: OS & Kernel ยท Systems Track ยท C++


๐Ÿงต Concurrency vs Parallelism

Concurrency: Dealing with multiple things at once (structure)
Parallelism: Doing multiple things at once (execution)

Concurrency is about composition. Parallelism is about speed.
Rob Pike

๐Ÿ“š Courses

Course Platform Link
Concurrent Programming in Java Coursera (audit, Rice) Coursera
Parallel Programming in Java Coursera (audit, Rice) Coursera
Performance Engineering (MIT 6.172) MIT OCW MIT OCW
Parallel Computer Architecture (NPTEL) NPTEL (IIT Kanpur) NPTEL
Real-Time Systems (NPTEL) NPTEL (IIT Kharagpur) NPTEL
Concurrency is Not Parallelism (Rob Pike) YouTube YouTube
The Art of Multiprocessor Programming (talks) YouTube YouTube

๐Ÿ”’ Concurrency Primitives

Primitive What When
Mutex Mutual exclusion lock Protect shared state
Semaphore Counting lock Limit concurrent access
Condition Variable Wait for a condition Producer-consumer
Read-Write Lock Multiple readers OR one writer Read-heavy workloads
Spinlock Busy-wait lock Very short critical sections
Atomic Operations Lock-free single-variable ops Counters, flags
Barrier Wait for all threads Parallel phases
Channel Message passing (Go, Rust) CSP-style concurrency
Future/Promise Async result Non-blocking I/O

๐Ÿ—๏ธ Concurrency Models

Model Language/Runtime Key Idea
Threads + Locks C, C++, Java Shared memory, explicit synchronization
CSP (Communicating Sequential Processes) Go (goroutines + channels) Don't share memory; share by communicating
Actor Model Erlang, Akka, Elixir Isolated actors, message passing
Async/Await Python, JS, Rust, C# Cooperative multitasking, event loop
Data Parallelism CUDA, OpenMP, SIMD Same operation on many data points
Fork-Join Java ForkJoinPool, Rayon (Rust) Divide work, join results
Software Transactional Memory Haskell, Clojure Database-like transactions for memory

๐Ÿ“… Scheduling

OS Scheduling Algorithms

Algorithm Type Use Case
FIFO (First Come First Served) Non-preemptive Batch processing
Round Robin Preemptive, time-slice General-purpose OS
Priority Scheduling Preemptive Real-time systems
Shortest Job First (SJF) Non-preemptive Batch optimization
Multilevel Feedback Queue Preemptive, adaptive Linux CFS inspiration
Completely Fair Scheduler (CFS) Preemptive Linux default
Earliest Deadline First (EDF) Preemptive Hard real-time
Rate Monotonic (RM) Static priority RTOS, periodic tasks

Real-Time Scheduling

โ†’ See Embedded Track

Concept What
Hard real-time Missing deadline = system failure
Soft real-time Missing deadline = degraded quality
Priority inversion Low-priority task blocks high-priority
Priority inheritance Temporarily boost blocking task
Watchdog timer Reset if task doesn't complete in time

Resources

Resource Link
OSTEP: Scheduling chapters ostep.org
Linux CFS explained kernel.org/doc
Real-Time Linux wiki.linuxfoundation.org/realtime

๐Ÿ”“ Lock-Free & Wait-Free Programming

Resource Link
Herb Sutter: Lock-Free Programming (CppCon) YouTube
Jeff Preshing: Lock-Free Blog preshing.com
Memory Models (C++ atomics) YouTube
Fedor Pikus: C++ Atomics (CppCon) YouTube

๐Ÿ› Common Concurrency Bugs

Bug What Prevention
Race Condition Outcome depends on timing Locks, atomics, immutability
Deadlock Threads wait for each other forever Lock ordering, timeouts
Livelock Threads keep retrying, no progress Backoff strategies
Starvation Thread never gets CPU time Fair scheduling, priority
Priority Inversion High-priority blocked by low-priority Priority inheritance
ABA Problem Value changes Aโ†’Bโ†’A, CAS succeeds incorrectly Hazard pointers, epoch-based reclamation

๐Ÿ“– Books

Book Free? Link
The Little Book of Semaphores โœ… greenteapress.com/semaphores
Is Parallel Programming Hard? โœ… kernel.org/pub/linux/kernel/people/paulmck/perfbook
OSTEP (Concurrency chapters) โœ… ostep.org
Java Concurrency in Practice โŒ (talks free) YouTube
C++ Concurrency in Action โŒ Reference
The Art of Multiprocessor Programming โŒ (lectures free) YouTube

Cross-references: OS & Kernel ยท C++ ยท Rust ยท Go ยท Embedded Track