Quantcast
Channel: std::atomic: Difference between x.fetch_add(1) and x++; - Stack Overflow
Browsing all 3 articles
Browse latest View live

Answer by Ciro Santilli OurBigBook.com for std::atomic: Difference between...

x.fetch_add(1) and x++ are exactly the same for std::atomicIf you believe cppreference, https://en.cppreference.com/w/cpp/atomic/atomic/operator_arith says:T operator++() volatile noexcept; (1)T*...

View Article



Answer by Anton for std::atomic: Difference between x.fetch_add(1) and x++;

The difference is definitely not about the safety = atomicity which is guaranteed for both methods.The most important difference I think is that fetch_add() can take a different memory order argument...

View Article

std::atomic: Difference between x.fetch_add(1) and x++;

What is the difference betweenextern std::atomic<int> x;int i = x++;andextern std::atomic<int> x;int i = x.fetch_add(1);I feel like the second version is safer, but I couldn't see any...

View Article
Browsing all 3 articles
Browse latest View live




Latest Images