~/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.

Coordination

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.

esc