I would like to use atomic variables in C.
I tried the following gcc built-in functions, but got a communication error undefined reference to `_sync_fetch_and_add' .
type __sync_fetch_and_add (type *ptr, type value); type __sync_fetch_and_sub (type *ptr, type value); type __sync_fetch_and_or (type *ptr, type value); type __sync_fetch_and_and (type *ptr, type value); type __sync_fetch_and_xor (type *ptr, type value); type __sync_fetch_and_nand (type *ptr, type value);
I assume that my architecture does not support them. I thought it was probably because it was not INTEL, but looking at the CPU information, I found that I have an Intel processor.
>less /proc/cpuinfo processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 26 model name : Intel(R) Xeon(R) CPU X5570 @ 2.93GHz stepping : 5 cpu MHz : 1600.000 >uname -a Linux xxxxxx 2.6.24.7-108.el5rt
Do you know other ways or libraries that atomic variables can implement for my architecture or if I am doing something wrong (maybe some flag compilations that I should check)?
NOTE. I found stdatomic.h , but only for C ++, unfortunately
Usage example:
int i =0; i = _sync_fetch_and_add (&i,2);
source share