title: builtin gcc spinlock
body: <p>How can I be sure the data that is written by multiple CPU cores during a mutex lock is synchronized across all L1 caches of all cores ? I am not talking about the variable that represents the lock, I am talking about the memory locations that are involved during the lock.</p>
  
  <p>This is for Linux, x86_64, and my code is:</p>
  
  <pre><code>#include &lt;sys/types.h&gt;
  #include "dlog.h"
  
  uint *dlog_line;
  volatile int dlog_lock;
  
  char *dlog_get_new_line(void) {
      uint val;
  
      while(!__sync_bool_compare_and_swap(&amp;dlog_lock, 0, 1)) {
          val=*dlog_line;
          if (val==DT_DLOG_MAX_LINES) val=0;
          *dlog_line=val;
      }
  
      dlog_lock = 0;
  }
  </code></pre>
  
  <p>Here, inside dlog_get_new_line() function, I use gcc builtin function so there shouldn't be any problem with aquiring the lock. But how can I ensure that when the lock is released, the value pointed by *dlog_line propagates into all the L1 cache of all the other CPU cores in the system?</p>
  
  <p>I do not use pthreads, each process runs on different cpu core.</p>