Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我发现lock inc addr,但这并没有保留存储值的副本,甚至在同一个线程中立即读取也可能发生在竞争写入之后。
lock inc addr
我发现的最佳解决方案是load//循环inc。cas
load
inc
cas
lock xadd是你的朋友。
lock xadd
有关更多 x86/x86_64 原子原语和用法,请参阅atomic_impl.h。