Synchronization PrimitivesSemaphoresMedium⏱️ ~2 min

The Rendezvous Pattern

Key Insight
A rendezvous is when two threads must both reach a certain point before either can proceed. Each thread waits for the other. This is bidirectional signaling.

The Puzzle

Given two threads, guarantee that a1 happens before b2 AND b1 happens before a2. Both threads must complete their first statement before either does their second.

Rendezvous Pattern
aArrived = 0, bArrived = 0Thread Astatement a1aArrived.signal()bArrived.wait()statement a2Thread Bstatement b1bArrived.signal()aArrived.wait()statement b2

Why Signal Before Wait?

If both threads wait first, deadlock! Thread A waits for B to signal, B waits for A to signal, nobody signals. By signaling first, you announce your arrival before checking if the other arrived.

Think Of It Like Meeting A Friend

You agree to meet at a coffee shop. When you arrive, you text "I'm here" (signal), then wait for their "I'm here" text (wait). If you both do this, you will find each other regardless of who arrives first.

The Barrier Generalization

Rendezvous is a two-thread barrier. Barriers generalize this to N threads: everyone must arrive before anyone proceeds. Useful for parallel algorithms where phases must synchronize.

Warning: Order matters! Signal then wait, never wait then signal, or you deadlock.
💡 Key Takeaways
Rendezvous: two threads wait for each other at a meeting point. Neither proceeds until both arrive.
Use two semaphores, one for each direction. Each thread signals its arrival, then waits for the other.
Signal before wait to avoid deadlock. If both wait first, both block forever.
Rendezvous generalizes to barriers where N threads all wait for each other.
This pattern is fundamental in parallel computing when phases must synchronize before continuing.
📌 Examples
1Game tick synchronization: physics thread and render thread rendezvous after each frame so neither gets ahead.
2Parallel merge sort: left and right halves computed in parallel, rendezvous before merging.
← Back to Semaphores Overview