std::atomic
看到有人讨论atomic是不是lockfree的
取决于硬件指令
The C++ standard recommends (but does not require) that lock-free atomic operations are also address-free, that is, suitable for communication between processes using shared memory.
https://en.cppreference.com/w/cpp/atomic/atomic_is_lock_free
测试实现
1 | #include <iostream> |
g++ a.cpp -std=gnu++11 -latomic
1 | std::atomic<A> is lock free? true |