How to use Compare and Swap (CAS) atomic function(Solaris specific) in C
807567Mar 15 2006 — edited Mar 27 2006Hi,
I have found cas32() atomic function in (solaris 10) </usr/include/sys/atomic.h> (and also there is another atomic.h header file in </usr/include/atomic.h> but this header file does not have any cas32() function declarations) the declaration of cas32 in <sys/atomic.h>
is as follows
extern uint32_t cas32(uint32_t *target, uint32_t cmp, uint32_t newval);
extern ulong_t caslong(ulong_t *target, ulong_t cmp, ulong_t newval);
extern uint64_t cas64(uint64_t *target, uint64_t cmp, uint64_t newval);
extern void casptr(void target, void cmp, void newval);
extern uint8_t cas8(uint8_t *target, uint8_t cmp, uint8_t newval);
But the problem is when iam using these functions in c programs and compiling
using gcc it is showing the following error.
-------------------------------------------------------------------------------
Undefined first referenced
symbol in file
cas32 /var/tmp//ccQcsnev.o
--------------------------------------------------------------------------------
And if i use the function other than cas32 group of instruction
such as atomic_or_uint()
whose declaration is extern void atomic_or_uint(uint_t *target, uint_t bits);
in <sys/atomic.h> it is giving no error where as for CAS32 it showing as undefined symbol.Why it is giving like that we are not able to know.Is it the case that CAS32 instruction only available in Kernel mode and not available to user mode.Please inform us if anyone knows how to use cas32() instruction in the user C programs.As this is usefull for writing Nonblocking versions of stacks and Queues.Is there any way to write
our own atomic functions?
Rama