title: Do multithreads operate atomic variables in multiple cores without locking?
body: <p>I have a question: I now use atomic operations in multiple threads. In the case of a single core, because it is a CPU, multiple threads do not need to lock when accessing the atomic variable v. however, in the case of a multi-core, because there are multiple CPUs and different threads running in different CPUs, there will be multiple threads operating the same atomic variable at the same time, It should be necessary to lock at this time. How can I lock it?</p>
  <p>Pseudo code：</p>
  <pre><code>thread_1_function()
  {
       ...
       //End of use
       atomic_store(&amp;v, 1);
       ...
  }
  thread_2_function()
  {
       ...
       atomic_store(&amp;v, 2);
       ...
  }
  thread_3_function()
  {
       ...
       atomic_load(&amp;v);
       if (i == 1)  {...}
       else if (i == 2) {...} 
       ...
  }
  </code></pre>