title: gcc atomic read and writes
body: <p>I have a multithreaded application where I one producer thread(main) and multiple consumers. </p>
  
  <p>Now from main I want to have some sort of percentage of how far into the work the consumers are. Implementing a counter is easy as the work that is done a loop. However since this loop repeats a couple of thousands of times, maybe even more than a million times. I don`t want to mutex this part. So I went looking into some atomic options of writing to an int.</p>
  
  <p>As far as I understand I can use the builtin atomic functions from gcc:
  <a href="https://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Atomic-Builtins.html" rel="nofollow">https://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Atomic-Builtins.html</a></p>
  
  <p>however, it doesn`t have a function for just reading the variable I want to work on. </p>
  
  <p>So basically my question is.</p>
  
  <ol>
  <li>can I read from the variable safely from my producer, as long as I use the atomic builtins for writing to that same variable in the consumer</li>
  </ol>
  
  <p>or</p>
  
  <ol>
  <li>do I need some sort of different function to read from the variable. and what function is that</li>
  </ol>