Building Blocks: Composing Signaling Patterns
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.
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.