CodingLevel 3

Concurrency

Easynot started
Mediumnot started
Hardnot started
Concurrency bugs in reviewWhy two threads modifying the same data at the same time destroys it.3 minConcurrency primitivesMultiple threads accessing shared resources must be coordinated to avoid deadlocks.3 minTwo writers, one resourceTwo people open the same record, both press save, and the second save quietly erases the first, unless the write is forced to say which version it was based on.7 minLock ordering (deadlock avoidance)How a simple alphabetical rule completely eliminates the possibility of a deadlock.3 minRace conditions and how a lock fixes themTwo threads reach for the same counter, step on each other, and an update quietly vanishes, a lock makes them take turns.4 minLock orderingSolving the Dining Philosophers problem by enforcing alphabetical order.3 minCheck-then-act (TOCTOU)Time-Of-Check to Time-Of-Use: Why looking before you leap fails in concurrency.3 minDeadlock and lock orderingWhen two database transactions wait for each other forever.3 minTwo writers, one file, a lost updateWhen both clients read the same value before either writes it back, the second write quietly paves over the first.4 minWorker thread pool exhaustionWhen every worker is stuck waiting on something slow, the queue keeps growing and new work just waits, even though the CPU is barely doing anything.4 minData racesWhen two threads try to use the same variable without taking turns.3 minPrompt craft for everyday workA useful first draft isn't luck, it's a prompt that leaves the model nothing to guess.4 minThe event loop (cooperative scheduling)How Node.js handles 10,000 connections with a single thread.3 minConcurrent modificationPulling the rug out from under an iterator.3 minFire and forget (async)Making things feel fast by doing the slow parts in the background.3 minStale reads and memory visibilityWhy Thread B doesn't see what Thread A just wrote.3 minAtomic writes: temp file then renameNever edit the live file in place, build the new version off to the side, then swap it in with one all-or-nothing rename.4 minLivelockWhen threads are too polite, resulting in an endless dance where nothing gets done.3 minNon-atomic counterWhy count++ is secretly three separate operations.3 minProducer-consumer (bounded buffer)Pacing the chefs so the waiters aren't overwhelmed.3 minShared mutable state (the Rust way)Why Rust forces you to choose between sharing and mutating.3 minThe stale leader problemA leader cut off by a partition may not know it was replaced, and keeps writing as if nothing changed.4 minAwait holding a lockWhy you should never go to sleep while holding the only key.3 minBarrier synchronizationMaking sure everyone finishes Phase 1 before anyone starts Phase 2.3 minConcurrency and interleavingWhy 1 + 1 sometimes equals 1 in distributed systems.3 minConcurrency backpressurePushing back on the producer when the consumer is overwhelmed.3 minConnection pool lock starvationWhen threads wait so long for a connection that the user gives up.3 minConnection pool race conditionsWhen two threads grab the exact same network socket.3 minDeadlock (cyclic acquisition)When two programs freeze forever because they each have what the other one wants.3 minDeadlock victim selectionWhen two transactions are frozen in a standoff, the database must assassinate one.3 minDurabilityA write isn't really safe until it has survived the fsync, buffers can vanish in a power cut.4 minLazy initialization raceCreating a heavy resource exactly once... or maybe twice?3 minMissing locks on compound operationsWhen two thread-safe actions combined create a thread-unsafe nightmare.3 minMutex contentionWhen many threads all want the same lock, they line up and wait, and the waiting, not the work, becomes the bottleneck.4 minRace condition detectionHow the compiler watches your threads and screams when they collide.3 minSemaphore permit leaksA semaphore is a tray of permits. Every borrower must put theirs back, one that forgets, even once, shrinks the tray forever.4 minSemaphores (permits)A bouncer for your resources: "Only 3 threads allowed inside at once."3 minSingle-threaded saturationOne worker can only do one thing at a time, when arrivals outpace its service rate, the queue backs up without bound.3 minThread-pool assignment orderThe order tasks are picked up is not the order they finish, a quick errand started later can beat a long one started first.3 minThread-unsafe lazy init (pre-C++11)When creating a Singleton causes undefined behavior in older C++.3 minTransaction deadlock stormTwo transactions politely wait for each other to let go, and so neither one ever does.3 min