Previous | Next --- Slide 27 of 51
Back to Lecture Thumbnails

Looking at the c++ reference for std::memory_order would give us a deeper understanding of the acquire/release mechanism. acquire typically comes with a load operation with this memory order performs the acquire operation on the affected memory location, and release typically comes with a store. Thinking about their relationship, we could see that acquire ensures that all writes in other threads that release the same atomic variable are visible in the current thread, and release makes all writes in the current thread are visible in other threads that acquire the same atomic variable.


am i right that memory_order only ensures load of ready is after store of it? also is there any use case where memory_order semantic might need more than a store-load operation?


@yangwu: From the link std::memory_order it is clear that the acquire/release semantics act like fences. It is not the case that memory order ensures load of ready after the corresponding store. memory_order_release ensures that no memory operations are reordered after this store, so all operations after this store will see this write to ready variable. memory_order_acquire ensures that no memory operations are reordered after this load, so all operations after this load will see this read from the ready variable.