Synchronization PatternsThread Signaling & CoordinationHard⏱️ ~2 min

Building Blocks: Composing Signaling Patterns

Key Insight
Complex synchronization problems are solved by combining simple patterns. Signaling, mutex, and multiplex are building blocks for everything else.

The Pattern Hierarchy

Start with signaling (one thread notifies another). Add mutual exclusion for shared data. Generalize to multiplex for bounded concurrency. Combine into rendezvous for mutual waiting. Extend to barriers for N threads. Each builds on the previous.

Pattern Building Blocks
SignalingMutexMultiplexRendezvousBarrierProducer-Consumer

Example: Building Producer-Consumer

You need: (1) Mutex - protect the queue from concurrent access. (2) Signaling - producer notifies consumer when item added. (3) Multiplex (optional) - limit queue size. Three simple patterns combine into a complete solution.

Example: Building a Barrier

A barrier is N-way rendezvous. Use: (1) Mutex - protect the arrival counter. (2) Counter - track how many threads arrived. (3) Signaling - last thread signals all others. The turnstile pattern lets all waiting threads through at once.

The Design Process

Step 1: Identify what events need ordering. What must happen before what? Step 2: Identify shared resources. What data do multiple threads access? Step 3: Match patterns to requirements. Signaling for ordering, mutex for protection, multiplex for capacity.

Think in Patterns: When you see a new synchronization problem, do not start from scratch. Ask: Is this signaling? Mutual exclusion? Bounded concurrency? Rendezvous? The answer is usually a combination.
💡 Key Takeaways
Complex synchronization is built from simple patterns. Signaling, mutex, and multiplex are the atoms.
Producer-consumer combines mutex (protect queue) + signaling (notify consumer) + optional multiplex (bound size).
Barriers combine mutex (protect counter) + counter (track arrivals) + signaling (release all threads).
Design process: Identify ordering requirements, identify shared resources, match to known patterns.
Most interview problems are combinations of 2-3 basic patterns. Recognize the pieces.
📌 Examples
1Bounded buffer: mutex + two counting semaphores (empty slots, full slots). Classic combination of patterns.
2Readers-writers: mutex + counter + signaling. Readers count themselves, signal writers when all done.
3Thread pool: multiplex (limit workers) + queue with producer-consumer pattern. Two patterns combined.
← Back to Thread Signaling & Coordination Overview
Building Blocks: Composing Signaling Patterns | Thread Signaling & Coordination - System Overflow