Reputation: 94800
I believe the answer is yes, much like in Java.
Please correct me if I am wrong.
If I need to just use mutual exclusion, I can use std::mutex
and others.
What if I need just sequential consistency and not mutual exclusion? What can be used for that?
Upvotes: 1
Views: 260
Reputation: 3403
The individual operations performed on objects of type std::atomic<whatever>
are atomic, but that's as far as it goes. So std::atomic<int>::fetch_add()
is atomic. But
std::atomic<int> x;
...
int tmp = x.load();
tmp += 1;
x.store(tmp);
Is just sequentially consistent, not atomic.
Upvotes: 0
Reputation: 490028
Yes -- see std::atomic
with memory_order_seq_cst
for sequential consistency.
Upvotes: 1