Is it necessary for all data accessing by multi-thread, decorated with volatile?
<p>For the primitive, I think it's necessary.
<strong>Even for the non-primitive, for example an array, I think it's also necessary.</strong></p>

<p>Without volatile:</p>

<pre><code>int d[2];
</code></pre>

<p>Thread 1:</p>

<pre><code>while (d[1] &gt; 0) modify(d[0]);
</code></pre>

<p>Thread 2:</p>

<pre><code>while (d[0] &gt; 0) modify(d[1]);
</code></pre>

<p>I am afraid that the compiler change my code as follow, when without volatile.
while (true) modify();</p>

<p>So I put volatile before 'int d[2]';
But I feel a little strange with everything decorated with volatile.</p>
