C++11 introduced the std::atomic<>
template library. The standard specifies the store()
and load()
operations to atomically set / get a variable shared by more than one thread.
My question is: are assignment and access operations also atomic? Namely, given
std::atomic<bool> stop(false);
!stop.load()
equivalent to !stop
?stop.store(true)
equivalent to stop = true
?Are assignment and access operations for non-reference types also atomic?
Yes, they are. atomic<T>::operator T
and atomic<T>::operator=
are equivalent to atomic<T>::load
and atomic<T>::store
respectively. All the operators are implemented in the atomic class such that they will use atomic operations as you would expect.
I'm not sure what you mean about "non-reference" types? Not sure how reference types are relevant here.