title: atomic variables in C
body: <p>I would like to use atomic variables in C. </p>
  
  <p>I tried the following suggested builtin functions in gcc but I received a link error <code>undefined reference to `_sync_fetch_and_add'</code>.</p>
  
  <pre><code>  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);
  </code></pre>
  
  <p>I am assuming that my architecture doesn't support them..I thought that probably because it is not INTEL but looking a the CPU info I discovered that I have Intel CPU.</p>
  
  <pre><code>  &gt;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
  
  
  
     &gt;uname -a
     Linux xxxxxx 2.6.24.7-108.el5rt #1 SMP PREEMPT RT 
     Mon Mar 23 10:58:10 EDT 2009      x86_64 x86_64 x86_64 GNU/Linux
  </code></pre>
  
  <p>Do you know other ways or libraries that might implement atomic variables for my architecture or if am I doing something wrong( maybe some compilation flags that I hould check out )?</p>
  
  <p>NOTE: I found <code>stdatomic.h</code> but is for C++ only unfortunately</p>
  
  <p>Usage example:</p>
  
  <pre><code>int i =0;
  i = _sync_fetch_and_add (&amp;i,2);
  </code></pre>