External Exercises
Practice concurrency fluency on external platforms after you have completed the concept pages, practice pages, and code katas in this module.
How To Use This Page
- Finish the relevant concept and the matching kata first.
- Solve at least one problem from memory.
- Only then open the exercise lane below.
- Keep a mistake log with tags such as
forgot while on cond wait,lock order violation,missing memory ordering,starved writer,ABA,blocked event loop.
Beginner Level
pthreads Fluency
- OSTEP Projects: Thread Create / Join / Mutex - Build the shared-counter and matrix-sum exercises from scratch until thread create/join/mutex are automatic.
- LearnCpp: std::thread and std::mutex chapters - Walk through the basic C++ examples and port them to pthreads.
- Exercism: Concurrency track (Go) - Short warm-ups on goroutines and channels for anyone newer to concurrency.
Shared State
- LeetCode 1114: Print in Order - Minimal coordination exercise; solve with mutex + condvar, then with semaphores.
- LeetCode 1115: Print FooBar Alternately - Two-thread ordering; forces explicit signaling.
- LeetCode 1116: Print Zero Even Odd - Three-thread coordination; natural fit for three condvars or three semaphores.
Intermediate Level
Bounded Buffer and Producer-Consumer
- LeetCode 1188: Design Bounded Blocking Queue - Canonical kata; implement with mutex + two condvars and with two semaphores. Compare.
- HackerRank: Multi-threading - Producer Consumer (search "producer consumer") - Large-workload variant.
- OSTEP Projects: Parallel Zip - Work queue driving parallel compression; good real-world bounded buffer.
Readers-Writers and Classical Problems
- LeetCode 1226: The Dining Philosophers - Implement deadlock-free. Compare ordering fix to arbitrator fix.
- OSTEP Projects: Web Crawler / Concurrent Web Server - Reader-writer lock patterns at scale.
Memory Ordering
- CppCon atomic examples (search "atomic" or "memory model") - Short snippets; reason about which ordering is minimal.
Advanced Level
Lock-Free Structures
- Michael-Scott Queue paper exercise - Implement the lock-free MPMC queue from the original paper.
- Treiber Stack with hazard pointers - Extend Kata 4 with a hazard-pointer reclamation scheme.
- ConcurrencyKit examples - Read the source of a production lock-free library; pick one structure and implement a simplified version.
Concurrency Debugging
- CS:APP Malloc Lab - Threadsafe - Harden a malloc implementation against concurrent callers.
- Jepsen writeups - Read a Jepsen analysis of a real system (MongoDB, Postgres, Cassandra). Map the failure back to a Coffman condition or a memory-ordering bug.
Systems Projects
- xv6 Concurrency Extensions - Add user-level threads, locks, and condition variables to xv6.
- The Little Book of Semaphores (Downey) - Work the "Cigarette Smokers", "H2O", and "Sushi Bar" problems. These are excellent beyond-the-textbook drills.
Completion Checklist
- Completed at least 3 beginner problems across different primitives
- Implemented the bounded blocking queue with both mutex+condvar and semaphores
- Implemented dining philosophers with a deadlock prevention fix and verified non-cyclic waits-for
- Attempted at least one advanced problem (Michael-Scott queue or hazard pointers)
- Mistake log contains at least 10 tagged entries with reproducible minimal examples
- Ran at least 2 programs under ThreadSanitizer and fixed anything it flagged