Leanpub Header

Skip to main content

Software Concurrency: Locks, Deadlocks and the Hidden Cost of Synchronization

A Practical Engineering Guide to Building Correct, Performant Concurrent Systems

Software Concurrency: Locks, Deadlocks and the Hidden Cost of Synchronization
This book is 100% completeLast updated on 2026-11-26

Concurrency is one of the hardest parts of systems programming, where a single mistake can lead to subtle bugs or serious performance problems. This book takes you from CPU architecture and memory models to locks, atomics and lock-free design, with practical code examples and real-world lessons to help you build concurrent systems that are both correct and fast.

Minimum price

$25.00

$35.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
WEB
APP
243
Pages
About

About

About the Book

This book is a comprehensive engineering reference on software concurrency, written for systems programmers, performance engineers and senior software engineers who need to build concurrent software that is both correct and fast. It takes you from the silicon level (how CPUs, caches and memory hierarchies actually work) through the operating system level (threads, scheduling, futexes) to the language level (memory models, atomics, synchronization primitives in C, C++, Rust, Java and Go) and finally to the architectural level (lock-free data structures, work-stealing schedulers, message passing and structured concurrency). Every major concept is accompanied by complete, compilable code examples, Mermaid diagrams and real-world case studies drawn from production systems. The book does not teach you how to add threads to a program; it teaches you how to think about concurrency as a first-class engineering discipline, where correctness is proven, performance is measured and every synchronization decision is deliberate.

Author

About the Author

Steve Publications

Steve is a technology professional with more than 20 years of experience spanning software development, server infrastructure, cybersecurity, vulnerability research and reverse engineering. His work focuses on understanding complex systems, uncovering security weaknesses and developing practical solutions that make technology more secure, reliable and effective.

Through Steve Publications, he collaborates with experienced researchers, engineers and industry experts to create practical, technically rigorous books on various topics not limited to self-improvement, software development, cybersecurity, cloud computing, DevOps, artificial intelligence and enterprise technologies. His mission is to make complex technical subjects accessible through clear explanations, real-world examples and hands-on exercises that help IT professionals, students and technology enthusiasts build valuable, practical skills.

Steve Publications embraces AI as a supporting tool for translation, proofreading and editorial refinement, not as a substitute for original research, technical expertise, or hands-on experience. Some contributors choose to publish under pseudonyms to protect their privacy or maintain professional boundaries.

Behind every book is a commitment to technical accuracy, practical relevance and continuous improvement. Our publications are written, reviewed and maintained by experienced professionals, with support from a private community of more than 420 engineers and researchers. Rather than prioritizing volume or mass-produced AI-generated content, we focus on delivering reliable, useful resources that readers can apply in real-world environments.

We also welcome experienced professionals who want to share their knowledge by writing or reviewing books, particularly in specialized and emerging technology fields. If you have expertise to contribute, we invite you to get in touch and explore opportunities to collaborate.

Our commitment is simple: To deliver books that respect our readers' time, support their professional growth and provide lasting practical value. If a book does not meet your expectations, Leanpub offers a 60-day money-back guarantee.

Contents

Table of Contents

A Practical Engineering Guide to Building Correct, Performant Concurrent Systems

Introduction: The Bug That Should Not Exist

Part I: Foundations

Chapter 1: Why Concurrency Is Hard

  1. The Economics of Parallelism
  2. A Taxonomy of Concurrency Bugs
  3. From Sequential to Concurrent: A Running Example

Chapter 2: Processes, Threads and Shared Memory

  1. Processes: Isolated Universes
  2. Threads: Shared Memory, Shared Responsibility
  3. Threads on Linux: The Clone System Call
  4. The Scheduler: Who Runs When?
  5. User-Mode Threads and the M:N Model
  6. Shared Memory: The Double-Edged Sword
  7. Thread-Local Storage: One Variable, Many Copies
  8. The Cost of a Context Switch
  9. Summary

Chapter 3: How CPUs Actually Work: Caches, Coherence and Reordering

  1. The Memory Hierarchy: Speed vs. Capacity
  2. Cache Coherence: The MESI Protocol
  3. Store Buffers and Write Buffering
  4. Out-of-Order Execution
  5. Compiler Reordering
  6. Atomic Operations: The Hardware’s Answer to Concurrency
  7. The x86 vs. ARM Divide
  8. Summary

Part II: Memory and Ordering

Chapter 4: Memory Models: From Hardware to Language

  1. Sequential Consistency: The Ideal
  2. The Message-Passing Pattern
  3. Acquire and Release Semantics
  4. The C++ Memory Ordering Hierarchy
  5. The Java Memory Model
  6. The Go Memory Model
  7. The Rust Memory Model
  8. Hardware Memory Models: x86 vs. ARM
  9. Memory Barriers
  10. The SC for DRF Theorem
  11. Summary

Chapter 5: Atomics and Memory Ordering in Practice

  1. The Atomic Building Blocks
  2. Memory Ordering in Practice
  3. A Visual Guide to Memory Orderings
  4. Performance Implications
  5. Common Patterns with Atomics
  6. Atomics in Other Languages
  7. Summary

Chapter 6: Data Races: Detection, Diagnosis and Prevention

  1. What Is a Data Race?
  2. Why Data Races Are So Dangerous
  3. How Data Races Occur
  4. Detecting Data Races
  5. Diagnosing Data Races
  6. Preventing Data Races
  7. A Visual Guide to Data Race Detection
  8. Real-World Data Race Bugs
  9. Summary

Part III: Locks

Chapter 7: Mutexes and the Art of Mutual Exclusion

  1. Mutual Exclusion
  2. The Running Example: Fixing the Broken Counter
  3. How Mutexes Work: From Lock to Futex
  4. Mutex Types
  5. Mutex Performance
  6. Mutex Patterns and Anti-Patterns
  7. Mutexes in Other Languages
  8. Summary

Chapter 8: Spinlocks, Semaphores and Condition Variables

  1. Spinlocks
  2. Semaphores
  3. Condition Variables
  4. Barriers
  5. Summary

Chapter 9: Read-Write Locks, Ticket Locks and Beyond

  1. Read-Write Locks
  2. Ticket Locks
  3. Queue-Based Locks (MCS and CLH)
  4. Hierarchical Locking and Lock Hierarchies
  5. Summary

Chapter 10: Locking in Practice: Granularity, Contention, Convoying and Priority Inversion

  1. Lock Granularity
  2. Lock Contention
  3. The Convoy Effect
  4. Priority Inversion
  5. Summary

Part IV: Failure Modes and Advanced Techniques

Chapter 11: Deadlocks, Livelocks and Starvation

  1. Deadlocks
  2. Livelocks
  3. Starvation
  4. The Dining Philosophers Problem
  5. Summary

Chapter 12: Lock-Free Programming: CAS and Beyond

  1. Motivation
  2. Compare-and-Swap (CAS)
  3. Lock-Free Data Structures
  4. The ABA Problem
  5. Progress Guarantees
  6. Transactional Memory
  7. Summary

Chapter 13: 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. Comparison of Memory Reclamation Techniques
  6. Summary

Chapter 14: Concurrent Data Structures

  1. Design Principles
  2. Concurrent Hash Tables
  3. Copy-on-Write Data Structures
  4. Concurrent Queues
  5. Concurrent Trees
  6. Summary

Part V: System Design

Chapter 15: Thread Pools, Work-Stealing and Scheduling

  1. Thread Pools
  2. Work-Stealing
  3. Summary

Chapter 16: Asynchronous Programming and Structured Concurrency

  1. Futures and Promises
  2. Async/Await
  3. Structured Concurrency
  4. Event Loops
  5. Summary

Chapter 17: Message-Passing and the Actor Model

  1. Message-Passing vs. Shared Memory
  2. Go Channels
  3. CSP (Communicating Sequential Processes)
  4. The Actor Model
  5. Message-Passing in Practice
  6. Summary

Part VI: Languages and Practice

Chapter 18: Concurrency Across Languages: C, C++, Rust, Java, Go

  1. The Five-Language Counter
  2. Memory Model Comparison
  3. Safety Guarantees Comparison
  4. Performance Comparison
  5. When to Use Each Language
  6. Summary

Chapter 19: Performance Engineering: Benchmarking and Profiling

  1. Benchmarking Methodology
  2. Profiling Tools
  3. Common Performance Pitfalls
  4. Performance Analysis of the Five-Language Counter
  5. Summary

Chapter 20: Design Principles and the Future of Concurrency

  1. Key Design Principles
  2. A Roadmap for Learning Concurrency
  3. The Future of Concurrency
  4. Final Thoughts

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