Module 3: Concurrency & Synchronization: Mistake Clinic
This clinic turns wrong moves into reusable judgment. Use it after each practice page and again before the quiz or checkpoint.
Module-Specific Mistake Radar
Start with these traps. Replace or extend them with real mistakes from your own work.
| Mistake to look for | Where it shows up | Symptom | Repair evidence |
|---|---|---|---|
| Finishing Race Condition and Locking Clinic with only a final answer | Race Condition and Locking Clinic | The work has no failed case, trace, test, proof gap, or design stress point. | Add the smallest broken example and show the repair that changes the result. |
| Finishing Coordination Primitive Workshop with only a final answer | Coordination Primitive Workshop | The work has no failed case, trace, test, proof gap, or design stress point. | Add the smallest broken example and show the repair that changes the result. |
| Finishing Deadlock and Lock-Free Reasoning Lab with only a final answer | Deadlock and Lock-Free Reasoning Lab | The work has no failed case, trace, test, proof gap, or design stress point. | Add the smallest broken example and show the repair that changes the result. |
| Finishing Code Katas with only a final answer | Code Katas | The work has no failed case, trace, test, proof gap, or design stress point. | Add the smallest broken example and show the repair that changes the result. |
| Treating Threads, Shared State, and Non-Atomic Operations as vocabulary instead of a tool | Threads, Shared State, and Non-Atomic Operations | The explanation names the concept but cannot decide between two cases. | Write one example, one non-example, and the rule that separates them. |
| Treating Race Conditions and the Critical Section as vocabulary instead of a tool | Race Conditions and the Critical Section | The explanation names the concept but cannot decide between two cases. | Write one example, one non-example, and the rule that separates them. |
Practice Mistake Checks
Pull any miss from these checks into your mistake log.
Race Condition and Locking Clinic
Source: practice/01-race-condition-and-locking-clinic.md
For each statement, identify the error and give the fix:
- "Reading a shared
intis atomic, so I can read it without a lock while another thread writes it." - "The test suite passed 1000 times; therefore the code has no race."
- "I used
if (!predicate) cond_wait(&cv, &m);because the signaler just woke someone, so the predicate must be true." - "My critical section is a single instruction, so I don't need a lock."
- "I only use spinlocks because they don't do a syscall, so they're always faster."
Coordination Primitive Workshop
Source: practice/02-coordination-primitive-workshop.md
Identify the bug in each:
-
pthread_mutex_lock(&m);
if (count == 0) pthread_cond_wait(&cv, &m); -
pthread_mutex_lock(&m);
ready = true;
pthread_mutex_unlock(&m);
pthread_cond_signal(&cv); // outside the lock -
Deadlock and Lock-Free Reasoning Lab
Source: practice/03-deadlock-and-lock-free-reasoning-lab.md
Diagnose each. Name the concurrency failure class:
- Two threads each call
transfer(a, b, 100)andtransfer(b, a, 50)respectively. The program hangs. (What failed? What fix?) - A lock-free queue works under load but leaks memory visibly over hours. (What failed?)
- A rwlock implementation passes correctness tests but on a 16-core server a writer waits 40 seconds to acquire while readers continuously enter. (What failed?)
- A CAS loop on a shared counter gets the correct sum under 2 threads but loses updates under 64 threads. (What could cause this?)
- A
sync.RWMutexprotected cache in Go gives correct results but CPU profiling shows huge time inruntime.semacquire. (What failed?)
Repair Protocol
For each real mistake:
- Reproduce the failure on the smallest example, trace, proof, query, command, or design sketch.
- Name the hidden assumption.
- Repair the artifact.
- Save evidence that changed: failing then passing test, corrected proof step, revised diagram, safer command, benchmark, or review note.
- Add one retrieval card beginning with Check... before... or Do not use... when....
Mistake Log
| Date | Mistake | Symptom | Root cause | Repair evidence | Retrieval card |
|---|---|---|---|---|---|
| Starter | Pick one radar row above | Explain how it would fail in this module | Name the assumption | Add a counterexample or corrected artifact | Write the card before closing the page |
Completion Standard
- At least five real mistakes are logged.
- At least two mistakes include a counterexample or failing test.
- At least one mistake connects to an older semester skill.
- At least one correction changes code, a proof, a diagram, a command transcript, a query, or a design decision.