Previous | Next --- Slide 35 of 43
Back to Lecture Thumbnails
MaxFlowMinCut

After looking through the C++ atomic docs, it doesn't appear that ++i is supported (where i is atomic<int> i as above).

Why is this the case? Shouldn't it simply be a matter of returning the incremented value instead of the pre-increment value when it's used in an [removed]just as you would normally use ++i even if it weren't atomic). Or did I simply misread the docs?

Note: The non-operator equivalent function call is fetch_add, which returns the value before the increment. There doesn't appear to be any add_fetch function.

bpr

@MaxFlowMinCut, reading the C++11 specification, the operations on atomics match the wiki link you provided. Oddly, both g++ and clang++ compiled "++i" without complaint. Looking at the assembly, the problem is that the x86 ISA provides xadd, which is fetch_add. Therefore, g++ and clang++ compile ++i as (pseudo-code equivalent) t = i++; return ++t;.