title: Is function call a memory barrier?
body: <p>Consider this C code:</p>
  
  <pre><code>extern volatile int hardware_reg;
  
  void f(const void *src, size_t len)
  {
      void *dst = &lt;something&gt;;
  
      hardware_reg = 1;    
      memcpy(dst, src, len);    
      hardware_reg = 0;
  }
  </code></pre>
  
  <p>The <code>memcpy()</code> call must occur between the two assignments. In general, since the compiler probably doesn't know what will the called function do, it can't reorder the call to the function to be before or after the assignments. However, in this case the compiler knows what the function will do (and could even insert an inline built-in substitute), and it can deduce that <code>memcpy()</code> could never access <code>hardware_reg</code>. Here it appears to me that the compiler would see no trouble in moving the <code>memcpy()</code> call, if it wanted to do so.</p>
  
  <p>So, the question: is a function call alone enough to issue a memory barrier that would prevent reordering, or is, otherwise, an explicit memory barrier needed in this case before and after the call to <code>memcpy()</code>?</p>
  
  <p><em>Please correct me if I am misunderstanding things.</em></p>