Synchronization Primitives • Mutexes & LocksEasy⏱️ ~2 min
Symmetric vs Asymmetric Solutions
Key Insight
When all threads run the same code with the mutex, the solution is symmetric. This is elegant because it generalizes easily to any number of threads.
Symmetric vs Asymmetric
Symmetric Example (Counter)
mutex.lock()
counter++
mutex.unlock()
counter++
mutex.unlock()
Every thread runs exactly this code. Add more threads? Same code. Simple and safe.
Asymmetric Example (Producer-Consumer)
Producer threads add items, consumer threads remove items. Different roles, different code. More complex to reason about.
Why Symmetric Is Preferred
Symmetric solutions are easier to verify. You only need to check one code path. Asymmetric solutions require checking all combinations of thread roles.
Design Rule: Prefer symmetric solutions when possible. They scale better and have fewer edge cases.
💡 Key Takeaways
✓Symmetric solution: all threads run the same code. Generalizes to any number of threads automatically.
✓Asymmetric solution: different threads run different code. Common in producer/consumer patterns.
✓Symmetric solutions are easier to verify because you only check one piece of code.
✓The mutex pattern is inherently symmetric: every thread does wait, critical section, signal.
✓Complex problems often require asymmetric solutions where threads have distinct roles.
📌 Examples
1Symmetric: N threads all increment a counter using the same mutex wait/signal pattern.
2Asymmetric: producer adds to queue, consumer removes from queue. Different code, shared semaphores.