Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 8d 09h 54m 29s8 days 9 hours 54 minutes 29 seconds.
Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 8d 09h 54m 29s8 days 9 hours 54 minutes 29 seconds.

Sign in to watch this lesson
The C++ Memory Model and Atomics · 4:03
memory_order_relaxed keeps exactly one thing: each variable's own modification order, which every thread moves down and never back up. Using the book's clerk with a notepad we see why two callers can hear different stories without anyone lying, and an Apple M3 confirms that no relaxed reader ever went backwards. Then the book's two-flag example breaks: in ten million runs the reader saw y true but x false 137 times, while release/acquire never failed. Relaxed is right for counters: four threads adding forty million times land exactly, with ldadd instead of ldaddal and no measurable speed difference on this Mac.