~/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.
Barrier
Rendezvous: n threads wait until all arrive.
Notes
Recognise it when: N threads work in phases and nobody may start phase p+1 until everyone has finished phase p.
barrier = threading.Barrier(n)
def worker(w):
for p in range(phases):
work(w, p)
barrier.wait()
Barrier vs Lock: a lock gives mutual exclusion (one at a time); a barrier is a rendezvous (all wait for all).
Gotchas: the party count must equal the number of threads that will call wait(), or everyone blocks.
2 problems
Concurrency
Coordination Semaphores, conditions and barriers.
Barrier
- Basics: build a reusable barrier basics easy
- Street lamps that copy their neighbours easy