~/problems
Problems
Basics first, then the classics, then company-style assessments. Every problem has tests you run right here; multi-level ones unlock as you go. See the roadmap.
Condition variable
wait_for(predicate) + notify_all; always include a termination case.
Notes
Recognise it when: "wait until some predicate over shared state holds": turn-taking, ordering, bounded queues.
cond = threading.Condition()
with cond:
cond.wait_for(lambda: done or my_turn()) # re-checks after every notify
if done: return
...mutate state...
cond.notify_all()
Gotchas
- Every predicate needs an escape clause (
done/i > n). Otherwise a waiter whose turn never comes hangs forever (the FizzBuzz TLE). - The method runs once per thread, so the loop goes inside it.
- After changing state,
notify_all(). Anyone waiting on a different predicate needs to re-check.
6 problems
Concurrency
Coordination Semaphores, conditions and barriers.
Condition variable
- Basics: countdown latch basics easy
- Baggage carousel easy
- FizzBuzz across four threads medium
- Interleave zeros, odds and evens medium
- Delayed task scheduler 2 levels ConfluentPinterest hard
- Durable multi-threaded log writer (group commit) 3 levels Databricks hard