How can an atomic operation be not a synchronization operation?
The standard says that a relaxed atomic operation is not a synchronization operation. But what's atomic about an operation result of which is not seen by other threads.The example here wouldn't give...
View ArticleAnswer by SergeyA for How can an atomic operation be not a synchronization...
Yes, standard is correct. Relaxed atomics are not synchronization operation, as only atomicity of operation is guaranteed.For example, int k = 5;void foo() { k = 10;}int baz() { return k;}In presence...
View ArticleAnswer by Brian Bi for How can an atomic operation be not a synchronization...
Suppose we havestd::atomic<int> x = 0;// thread 1foo();x.store(1, std::memory_order_relaxed);// thread 2assert(x.load(std::memory_order_relaxed) == 1);bar();There is, first of all, no guarantee...
View ArticleAnswer by rustyx for How can an atomic operation be not a synchronization...
The compiler and the CPU are allowed to reorder memory accesses. It's the as-if rule and it assumes a single-threaded process.In multithreaded programs, the memory order parameter specifies how memory...
View Article