Explain the C++ memory model and memory ordering constraints.
Answer
C++11 memory model defines how threads observe writes from other threads. Memory orderings: seq_cst (strongest, default - total order), acquire (reads after this see writes before release), release (writes before this visible after acquire), relaxed (no ordering guarantees, only atomicity). acquire-release: synchronizes between threads. seq_cst for safety, relaxed for performance-critical counters. memory_order_consume (rarely used). Fences: atomic_thread_fence for explicit barriers. Hardware: strong ordering (x86) vs weak (ARM). Use: load(acquire), store(release) for typical producer-consumer. Profile before weakening ordering.
Master These Concepts with IIT Certification
175+ hours of industry projects. Get placed at Bosch, Tata Motors, L&T and 500+ companies.