Synchronization PatternsThread Signaling & CoordinationMedium⏱️ ~2 min

The Rendezvous Pattern

Definition
A rendezvous is when two threads must both reach a certain point before either can proceed. They meet at the rendezvous point and continue together.

Why Mutual Waiting?

Basic signaling is one-way: A signals B. But sometimes both threads need to wait for each other. Thread A does part 1, Thread B does part 1. Neither can do part 2 until both finish part 1. They must synchronize at a meeting point.

The Airport Gate Analogy

Two friends flying from different cities meet at a connecting airport. Alice lands at 2pm, Bob at 3pm. Alice waits at the gate. When Bob arrives, they both proceed to the next flight together. Neither boards until both have arrived.

Rendezvous: Both Threads Wait
Thread AThread Bstatement a1statement b1aArrived.signal()bArrived.signal()bArrived.wait()aArrived.wait()statement a2statement b2

The Solution

Use two semaphores, both initialized to 0. Each thread signals its own "arrived" semaphore, then waits on the other. The order is critical: signal first, then wait. Reversing this causes deadlock.

Why Signal Before Wait?

If both threads wait before signaling, both block forever. Neither can signal because both are stuck waiting. This is deadlock. By signaling first, at least one thread makes progress even if it then blocks.

Deadlock Trap: Swapping the order to wait-then-signal causes deadlock. If A waits for B and B waits for A, and neither has signaled yet, both block forever.
💡 Key Takeaways
Rendezvous requires two threads to reach a point before either continues. It is mutual waiting, not one-way signaling.
Use two semaphores, one per thread, both initialized to 0. Each thread signals its own, waits on the other.
Signal before wait is mandatory. Wait before signal causes deadlock - both threads block forever.
Neither thread can proceed past the rendezvous until both have arrived. This guarantees synchronization.
Rendezvous is the foundation for barriers. A barrier is just rendezvous generalized to N threads.
📌 Examples
1Parallel computation: Two threads compute partial results. Both must finish before either can combine them into final answer.
2Game synchronization: Player 1 and Player 2 both submit moves. Neither sees results until both have submitted.
3Distributed consensus: Two nodes exchange messages. Neither commits until both acknowledge receipt.
← Back to Thread Signaling & Coordination Overview