title: Can shared memory be read and validated without mutexes?
body: <p>On Linux I'm using <code>shmget</code> and <code>shmat</code> to setup a shared memory segment that one process will write to and one or more processes will read from.  The data that is being shared is a few megabytes in size and when updated is completely rewritten; it's never partially updated.</p>
  
  <p>I have my shared memory segment laid out as follows:</p>
  
  <pre>
      -------------------------
      | t<sub>0</sub> | actual data | t<sub>1</sub> |
      -------------------------
  </pre>
  
  <p>where t<sub>0</sub> and t<sub>1</sub> are copies of the time when the writer began its update (with enough precision such that successive updates are guaranteed to have differing times).  The writer first writes to t<sub>1</sub>, then copies in the data, then writes to t<sub>0</sub>.  The reader on the other hand reads t<sub>0</sub>, then the data, then t<sub>1</sub>.  If the reader gets the same value for t<sub>0</sub> and t<sub>1</sub> then it considers the data consistent and valid, if not, it tries again.</p>
  
  <p>Does this procedure ensure that if the reader thinks the data is valid then it actually is?</p>
  
  <p>Do I need to worry about out-of-order execution (OOE)?  If so, would the reader using <code>memcpy</code> to get the entire shared memory segment overcome the OOE issues on the reader side?  (This assumes that <code>memcpy</code> performs it's copy linearly and ascending through the address space.  Is that assumption valid?)</p>