As far as I know, atomic operations of atomic type in cpp11 are guaranteed to be aomtic. However, suppose in multi-core system, if two threads do following operation simultaneously, will the result be 1?(suppose initially atomic<int> val=0
;) It seems that the result is guaranteed to be 2, but why?
val.fetch_add(1,std::memory_order_relaxed);
As a supplement, suppose another situation, if thread1 do val.load(2);
thread2 do val.load(3)
, it seems that the result is whether 2 or 3,but not certain which one either.