Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is ++ atomic for std::atomic<int>

Tags:

c++11

atomic

Acording to one Channel 9 E2E video(with Herb Sutter in it) in c++0x if number is atomic<int> number++ is atomic. Can somebody confirm that is how it is in the final C++11 standard(lets pretend that it is finalized :)).

like image 455
NoSenseEtAl Avatar asked Jul 27 '11 13:07

NoSenseEtAl


1 Answers

The standard is finalised, and every operation on all the standard integral specialisations of atomic<T> is atomic.

This doesn't mean all expressions involving standard integral atomic<T> are atomic.

number = number * 2;

is two operations:

temporary = number * 2;
number = temporary;

Each of them is atomic, but together they are not. This is what transactions/critical sections are for.

like image 83
spraff Avatar answered Nov 18 '22 10:11

spraff