I'm studying the difference between mutex
and atomic
in C++11.
As my understanding, mutex
is a kind of lock-mechanism, which is implemented based on the OS/kernel. For example, Linux offers a mechanism, which is futex
. With the help of futex
, we could implement mutex
and semaphore
. Furthermore, I've known that futex
is implemented by the low-level atomic operation, such as CompareAndSet
, CompareAndSwap
.
For std::atomic
, I've known that it is implemented based on the memory model, which is introduced by C++11. However, I don't know how the memory model is implemented at the low level. If it is also implemented by the atomic operation like CompareAndSet
, what is the difference between std::atomic
and mutex
?
In a word, if std::atomic::is_lock_free
gives me a false
, well, I'm gonna say that std::atomic
is the same with mutex
. But if it gives me a true
, how is it implemented at low level?
std::atomic
is implemented differently on different architectures, I think only one example based on some specific architecture is enough for me, for example, X86. – Aurelio