oz10
oz10

Reputation: 158574

High-level Compare And Swap (CAS) functions?

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.

Upvotes: 13

Views: 8943

Answers (7)

C. K. Young
C. K. Young

Reputation: 223213

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

Upvotes: 6

seh
seh

Reputation: 15269

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.

Upvotes: 2

Ben Combee
Ben Combee

Reputation: 17427

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.

Upvotes: 9

Andreas Petersson
Andreas Petersson

Reputation: 16518

java has this CAS operation, too

see here

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

Upvotes: 1

Don Neufeld
Don Neufeld

Reputation: 23248

MacOS X has OSAtomic.h

Upvotes: 2

Christian.K
Christian.K

Reputation: 49320

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

Upvotes: 2

Michael Burr
Michael Burr

Reputation: 340516

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".

Upvotes: 17

Related Questions