<p>let's say we have a c++ class like:</p>

<pre><code>class MyClass
{
   void processArray( &lt;an array of 255 integers&gt; )
   {
     int i ;
     for (i=0;i&lt;255;i++)
     {
        // do something with values in the array
     }
   }
}
</code></pre>

<p>and one instance of the class like:  </p>

<pre><code>MyClass myInstance ;
</code></pre>

<p>and 2 threads which call the processArray method of that instance (depending on how system executes threads, probably in a completely irregular order). There is no mutex lock used in that scope so both threads can enter.</p>

<p><strong>My question is what happens to the i ? Does each thread scope has it's own "i" or would each entering thread modify i in the for loop, causing i to be changing weirdly all the time.</strong> </p>

```
i
```
is allocated on the stack.  Since each thread has its own separate stack, each thread gets its own copy of
```
i
```
.