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

Sign in to watch this lesson
The C++ Memory Model and Atomics · 4:19
How an atomic flag makes ordinary data safe to share. Inside a thread, statements are sequenced before one another (but function arguments are not); between threads, a store synchronizes with the load that reads its value, and happens-before chains the two, so the writer's push_back happens before the reader's data[0]. We ran the book's flag-plus-data handoff 100,000 times on a Mac and always read 42; with relaxed atomics, a litmus test saw the flag set but the data missing over two thousand times in ten million runs, while release/acquire and seq_cst never did, and ThreadSanitizer flagged the relaxed handoff as a data race.