High-level Compare And Swap (CAS) functions?

随声附和 提交于 2019-11-28 23:02:26

问题


I'd like to document what high-level (i.e. C++ not inline assembler ) functions or macros are available for Compare And Swap (CAS) atomic primitives...

E.g., WIN32 on x86 has a family of functions _InterlockedCompareExchange in the <_intrin.h> header.


回答1:


I'll let others list the various platform-specific APIs, but for future reference in C++09 you'll get the

atomic_compare_exchange() 

operation in the new "Atomic operations library".




回答2:


glib, a common system library on Linux and Unix systems (but also supported on Windows and Mac OS X), defines several atomic operations, including g_atomic_int_compare_and_exchange and g_atomic_pointer_compare_and_exchange.




回答3:


GCC has some built-ins for atomic accesses, too.




回答4:


On Solaris there is "atomic.h" (i.e. <sys/atomic.h>).




回答5:


MacOS X has OSAtomic.h




回答6:


There have been a series of working group papers on this subject proposing changes to the C++ Standard Library. WG N2427 (C++ Atomic Types and Operations) is the most recent, which contributes to section 29 -- Atomic operations library -- of the pending standard.




回答7:


java has this CAS operation, too

see here

there are practical uses for this, like a lock-free hashtable used in multiprocessor system



来源:https://stackoverflow.com/questions/151841/high-level-compare-and-swap-cas-functions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!