knaxuslearn · build · ship

Roadmaps / Fundamentals / Phase 3

Phase 3 of 4 · Study weeks 9-12

Concurrency

This phase makes the third checkpoint possible: a server that shares state across threads without races or deadlocks.

Topics every week

  1. Week 98 h
    • Threads, locks and condition variables
    • Races and what a data race is
    • Atomics and memory ordering
    • The memory model of your language

    Hand inThe shared queue with a lock and a measured cost per operation

  2. Week 108 h
    • Race detection: Go race detector, ThreadSanitizer, Java stress harnesses
    • Stress testing
    • Seeding a race on purpose

    Hand inThe seeded race caught by a tool and fixed

  3. Week 118 h
    • Deadlock, livelock and starvation
    • Lock ordering
    • Thread dumps
    • Timeouts and cancellation

    Hand inThe seeded deadlock found from a thread dump and a lock-order rule

  4. Week 128 h
    • Channels, queues and actors against shared state
    • Backpressure
    • False sharing and cache lines
    • Predicted against measured

    Hand inCheckpoint 3: the stress run, the tool output and the throughput table

Practice projects

  • Practice 1, the lost update (Week 9): increment a shared counter from 8 threads without a lock. Done when: the final count is wrong, you explain why and three fixes (lock, atomic, per-thread counters) are measured.
  • Practice 2, the tool run (Week 10): run the race detector or ThreadSanitizer on the server. Done when: it flags the seeded race with a stack trace and passes after the fix.
  • Practice 3, the deadlock (Week 11): take two locks in opposite order. Done when: a thread dump shows the cycle, and your lock-order rule makes it impossible and is tested.
  • Optional, false sharing: place two counters on one cache line, then on separate ones. Done when: a table shows the difference and you say when it matters.

GitHub repos to study

Existence and last commit were checked on 22 Nov 2026 by shallow clone. Every repository below had a commit in the last 12 months.

RepoWhat to readWeek
google/sanitizersThe ThreadSanitizer algorithm notes and flags10
JCTools/JCToolsHow a concurrent queue is built and tested12
facebook/follySynchronisation primitives and their documentation9
google/guavaConcurrency utilities and their contracts12

Milestone checkpoint

Build Checkpoint 3. Write the stress test and the deadlock scenario first. Add the shared queue, run the tool, seed the race and the deadlock, and fix each from the evidence. Write the lock-order rule in the README. Hand in the tool output, the thread dump, the throughput table, ADR-5 (the sharing model) and ADR-6 (the lock-order rule).

Check yourself

Answer each question in your head first, then open it to check.

  1. What is a data race, and why does it cause trouble even when the result looks right?
    Two threads access the same memory, at least one writes and nothing orders them. The language then makes no promise about the result, and the compiler and the CPU may reorder operations.
  2. What does a race detector miss?
    Races that did not happen in this run, and logic errors that are not data races, such as an invariant that spans two variables.
  3. What are the four conditions for deadlock, and how does lock ordering remove one?
    Mutual exclusion, hold and wait, no preemption and circular wait. A global lock order removes circular wait.
  4. When is an atomic enough, and when do you need a lock?
    An atomic is enough for one variable updated on its own. You need a lock when an invariant spans several variables.
  5. Why does a queue with a bound help?
    A full queue pushes back on the producer, so overload shows up as waiting at the source, not as memory growth.