Leanpub Header

Skip to main content

The Art of Concurrent Programming

Locks, Atomics, Lock-Free Systems and High-Performance Concurrent Software

The Art of Concurrent Programming
This book is 100% completeLast updated on 2026-10-06

Concurrency is where small mistakes become serious problems. This practical guide takes you from hardware and memory models to locks, atomics and lock-free algorithms, with a focus on building fast, reliable systems that hold up under real production workloads.

Minimum price

$25.00

$35.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
WEB
APP
261
Pages
About

About

About the Book

This book is a complete technical guide to building correct, efficient concurrent software for production systems. It covers the full stack from hardware architecture and memory models through synchronization primitives, lock-free algorithms, debugging techniques, performance engineering, and real-world architecture patterns. The audience is experienced software engineers who need to design, implement, benchmark, and operate reliable concurrent systems at scale, and who want to understand not just what works, but why, what can go wrong, and how to choose between alternatives when trade-offs matter.

Author

About the Author

Steve Publications

Steve is a technology professional with over 20 years of experience in software development, server infrastructure, cybersecurity, vulnerability research and reverse engineering. He specializes in analyzing complex systems, identifying weaknesses and improving security.

Beyond his professional work, Steve collaborates with researchers and industry experts to create practical technical books covering software development, cybersecurity, cloud computing, DevOps, AI and enterprise technologies. His goal is to help IT professionals, students and enthusiasts develop practical skills through clear explanations, real-world examples and hands-on exercises.

At Steve Publications, we use AI to assist with translation, proofreading and editing but not to replace the research, technical expertise or hands-on experience behind our books. Some authors publish under pseudonyms for privacy or professional reasons.

Every book is written, reviewed and maintained by experienced professionals, supported by a private community of over 420 engineers and researchers. We prioritize technical accuracy, practical value and regularly updated content over mass-produced AI-generated text.

We welcome experienced professionals interested in writing or reviewing books, especially in specialized and emerging technology fields. If you'd like to contribute, contact us with your area of expertise.

We stand behind our work. If a book doesn't meet your expectations, Leanpub offers a 60-day money-back guarantee.

Contents

Table of Contents

Locks, Atomics, Lock-Free Systems and High-Performance Concurrent Software

  1. Introduction

Chapter 1: Concurrency vs Parallelism: Defining the Problem

  1. What Concurrency Actually Means
  2. Concurrency Without Parallelism
  3. The Cost of Getting It Wrong
  4. Why Modern Hardware Demands Concurrency
  5. The Trade-off Landscape

Chapter 2: Processes, Threads and the Operating System

  1. The Unix Process Model
  2. Kernel Threads and User Threads
  3. Context Switching and Its True Cost
  4. Scheduling Policies and Predictability
  5. M:N Thread Models and Goroutines

Chapter 3: Inside the CPU: Cores, Caches and Coherence

  1. CPU Cores and Hardware Threads
  2. The Memory Hierarchy and Cache Lines
  3. MESI and Cache Coherence Protocols
  4. NUMA Architectures and Their Consequences
  5. Memory Buses and Interconnect Latencies

Chapter 4: False Sharing, Contention and Cache Thrashing

  1. The Anatomy of False Sharing
  2. Detecting False Sharing in Practice
  3. Memory Allocation Under Concurrency
  4. Cache Thrashing and Its Symptoms
  5. Designing for Cache-Line Awareness

Chapter 5: How CPUs Reorder Memory Access

  1. Why CPUs Reorder Instructions
  2. The x86-64 Memory Model
  3. ARM and Weakly Ordered Architectures
  4. Compiler Reordering vs Hardware Reordering
  5. What This Means for Correct Code

Chapter 6: The Happens-Before Relation

  1. Defining Happens-Before
  2. Program Order and Sequential Execution
  3. Synchronization Order and Atomic Operations
  4. Visibility Guarantees and Their Limits
  5. Reasoning About Correctness with Happens-Before

Chapter 7: Consistency Models: From Sequential to Linearizable

  1. Sequential Consistency and Its Promise
  2. Why Sequential Consistency Is Expensive
  3. Linearizability and Its Real-Time Guarantees
  4. Relaxed Consistency and When It Is Safe
  5. Choosing the Right Consistency Model

Chapter 8: Atomic Primitives and Memory Ordering

  1. Atomicity and What It Actually Guarantees
  2. Sequentially Consistent Atomics
  3. Acquire and Release Semantics
  4. Relaxed Atomics and Their Danger Zones
  5. Memory Fences and Barrier Instructions

Chapter 9: Compare-and-Swap and Read-Modify-Write Operations

  1. How Compare-and-Swap Works
  2. CAS at the Hardware Level
  3. Fetch-and-Add and Other RMW Operations
  4. The ABA Problem in Detail
  5. Tagged Pointers and Version Counters

Chapter 10: Language-Level Memory Models: C/C++, Java, Rust, Go

  1. The C11/C++11 Memory Model
  2. Java’s Happens-Before Semantics
  3. Rust’s Approach to Concurrency
  4. Go’s Simpler Memory Guarantees
  5. Mapping Between Language Models

Chapter 11: Progress Guarantees and Fairness

  1. What It Means for a System to Make Progress
  2. Lock-Based (Blocking) Algorithms
  3. Lock-Free Algorithms
  4. Wait-Free Algorithms
  5. Fairness and Starvation
  6. Priority Inversion
  7. Deadlock, Livelock and Starvation
  8. Choosing Progress Guarantees

Chapter 12: Mutexes and Futexes

  1. What a Mutex Actually Does
  2. Futexes: How Modern Mutexes Work
  3. Spinlocks
  4. Recursive Mutexes
  5. Mutex Performance and Scalability

Chapter 13: Read-Write Locks, Barriers and Condition Variables

  1. Read-Write Locks
  2. Condition Variables
  3. Barriers
  4. Semaphores
  5. Monitors
  6. When to Use Which Primitive

Chapter 14: Specialized Locks: Ticket Locks, MCS Locks and Seqlocks

  1. Why Specialized Locks Exist
  2. Ticket Locks
  3. MCS Locks
  4. Q-locks and CLH Locks
  5. Seqlocks
  6. Choosing a Lock for High Contention

Chapter 15: Lock-Free Programming Fundamentals

  1. When Lock-Free Is Worth It
  2. The CAS Loop Pattern
  3. Lock-Free vs Wait-Free vs Blocking
  4. ABA in Lock-Free Structures
  5. Memory Ordering in Lock-Free Code

Chapter 16: Reference Counting and Atomic Pointers

  1. Why Reference Counting Matters in Concurrency
  2. Atomic Reference Counting
  3. Optimized Reference Counting
  4. Control Blocks and Shared State
  5. Reference Counting and Lock-Free Structures

Chapter 17: Lock-Free Stacks, Queues and Ring Buffers

  1. The Treiber Stack
  2. The Michael-Scott Queue
  3. Single-Producer Single-Consumer Ring Buffer
  4. Multi-Producer Multi-Consumer Ring Buffer
  5. When to Use Which Structure

Chapter 18: Memory Reclamation: Hazard Pointers, EBR and RCU

  1. The Memory Reclamation Problem
  2. Hazard Pointers
  3. Epoch-Based Reclamation (EBR)
  4. RCU (Read-Copy-Update)
  5. Comparing Memory Reclamation Techniques

Chapter 19: Concurrent Hash Maps and Scalable Data Structures

  1. Why Hash Maps Are Hard in Concurrency
  2. Lock-Striped Hash Map
  3. Java’s ConcurrentHashMap
  4. C++ and the Lack of Standard Concurrent Containers
  5. Immutable and Copy-on-Write Maps
  6. When to Use Which Approach

Chapter 20: Diagnosing Data Races and Visibility Bugs

  1. Why Data Races Are Insidious
  2. Symptoms of Data Races
  3. ThreadSanitizer (TSan)
  4. Java ThreadSanitizer Alternatives
  5. Rust’s Compile-Time Prevention
  6. Go’s Race Detector
  7. Lockset Algorithms
  8. Static Analysis for Races
  9. Best Practices for Race Detection

Chapter 21: Debugging Deadlocks, Livelocks and Starvation

  1. Deadlock Detection in Production
  2. Thread Dump Analysis
  3. Deadlock Detection Algorithms
  4. Preventing Deadlock
  5. Livelock Detection
  6. Starvation Detection
  7. Tools for Debugging Liveness Bugs

Chapter 22: Concurrency Testing and Verification

  1. Why Normal Testing Is Not Enough
  2. Stress Testing
  3. Property-Based Testing for Concurrency
  4. Model Checking
  5. Deterministic Concurrency Testing
  6. Fuzzing for Concurrency Bugs
  7. Verification for Lock-Free Algorithms
  8. Testing Checklist

Chapter 23: Performance Profiling and Analysis

  1. Measuring What Matters
  2. Flame Graphs for Concurrent Code
  3. Per-Thread and Per-Core Analysis
  4. Cache Performance Analysis
  5. Lock Contention Analysis
  6. Context Switch and Scheduler Analysis
  7. Tools Summary

Chapter 24: Benchmarking Methodology for Concurrent Systems

  1. Why Benchmarking Concurrent Code Is Hard
  2. Controlling Environmental Variables
  3. Measuring Distributions, Not Averages
  4. Scalability Testing
  5. Avoiding Benchmark Artifacts
  6. Comparing Synchronization Strategies
  7. Benchmarking Checklist

Chapter 25: Concurrency Design Patterns and Trade-Offs

  1. Thread Pools
  2. Work Stealing
  3. Futures and Promises
  4. Message Passing and Channels
  5. Sharding and Partitioning
  6. Choosing the Right Pattern

Chapter 26: Production Architectures and Case Studies

  1. High-Throughput Web Servers
  2. Database Concurrency: MVCC and Latching
  3. Redis: Single-Threaded with Clustering
  4. Kafka: Partitioned Log with Concurrent Consumers
  5. Go Runtime: M:N Scheduling
  6. Lessons from Production

Chapter 27: Advanced Topics and Language-Specific Patterns

  1. C++ Concurrency Best Practices
  2. Rust Concurrency Best Practices
  3. Go Concurrency Best Practices
  4. Java Concurrency Best Practices
  5. Real-Time and Safety-Critical Concurrency
  6. Emerging Trends

Chapter 28: Design Principles and Anti-Patterns

  1. Principles for Reliable Concurrent Systems
  2. Common Anti-Patterns
  3. Decision Framework
  4. The Lock-Free Decision
  5. Final Wisdom

Chapter 29: Conclusion: Building Production-Ready Concurrent Systems

  1. The Journey from Fundamentals to Production
  2. The Hierarchy of Concurrency Solutions
  3. Correctness Before Performance
  4. Embracing Complexity Responsibly
  5. The Role of Hardware
  6. A Lasting Perspective
  7. References

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub