title: When manipulating different array indices in C/C++ with two threads, is synchronization needed?
body: <p>Suppose I have an array defined as follows:</p>
  
  <pre><code>volatile char v[2];
  </code></pre>
  
  <p>And I have two threads (denoted by A, B respectively) manipulating array <code>v</code>. If I ensure that A, B use different indices at any time, that is to say, if A is now manipulating <code>v[i]</code>, then B is either doing nothing, or manipulating <code>v[1-i]</code>. I wonder is synchronization needed for this situation?</p>
  
  <p>I have referred to <a href="https://stackoverflow.com/questions/940139/is-synchronization-needed-when-manipulating-different-arrayobject-array-indice">this question</a>, however I think it is limited in Java. The reason why I ask this question is that I have been struggling with a strange and rare bug in a large project for days, and up to now, the only reason I could come up with to explain the bug is that synchronization is needed for the above manipulation. (Since the bug is very rare, it is hard for me to prove whether my conjecture is true)</p>
  
  <p>Edit: both reading and modifying are possible for <code>v</code>.</p>