Skip to main content

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 forWhere it shows upSymptomRepair evidence
Finishing Race Condition and Locking Clinic with only a final answerRace Condition and Locking ClinicThe 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 answerCoordination Primitive WorkshopThe 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 answerDeadlock and Lock-Free Reasoning LabThe 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 answerCode KatasThe 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 toolThreads, Shared State, and Non-Atomic OperationsThe 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 toolRace Conditions and the Critical SectionThe 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:

  1. "Reading a shared int is atomic, so I can read it without a lock while another thread writes it."
  2. "The test suite passed 1000 times; therefore the code has no race."
  3. "I used if (!predicate) cond_wait(&cv, &m); because the signaler just woke someone, so the predicate must be true."
  4. "My critical section is a single instruction, so I don't need a lock."
  5. "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:

  1. pthread_mutex_lock(&m);
    if (count == 0) pthread_cond_wait(&cv, &m);
  2. 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:

  1. Two threads each call transfer(a, b, 100) and transfer(b, a, 50) respectively. The program hangs. (What failed? What fix?)
  2. A lock-free queue works under load but leaks memory visibly over hours. (What failed?)
  3. 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?)
  4. A CAS loop on a shared counter gets the correct sum under 2 threads but loses updates under 64 threads. (What could cause this?)
  5. A sync.RWMutex protected cache in Go gives correct results but CPU profiling shows huge time in runtime.semacquire. (What failed?)

Repair Protocol

For each real mistake:

  1. Reproduce the failure on the smallest example, trace, proof, query, command, or design sketch.
  2. Name the hidden assumption.
  3. Repair the artifact.
  4. Save evidence that changed: failing then passing test, corrected proof step, revised diagram, safer command, benchmark, or review note.
  5. Add one retrieval card beginning with Check... before... or Do not use... when....

Mistake Log

DateMistakeSymptomRoot causeRepair evidenceRetrieval card
StarterPick one radar row aboveExplain how it would fail in this moduleName the assumptionAdd a counterexample or corrected artifactWrite 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.