One is a member function of template class std::atomic
, one is template function, seems they do the same thing. As std
is a class library, why it provides both class and none-class version of, I think the same operation?
Is there any real differences between them?
There's no difference in semantics. The free functions were an attempt to achieve source compatibility with C11:
#ifdef __cplusplus
#include <atomic>
#define _Atomic(X) std::atomic<X>
#else
#include <stdatomic.h>
#endif
_Atomic(int) c;
int get_c(void) {
return atomic_load(&c);
}
Just like you said - one is a class, another is a function. Class have the interface - atomic<T>
would provide for stores, loads, proper constructors, etc.
On the other hand, atomic_store
could be specialized for your types.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With