title: Why does similar code running in multiple threads have different running times?
body: <p>I met a very strange problem about a C++ multi-thread program which as belows.</p>
  <pre><code>#include&lt;iostream&gt;
  #include&lt;thread&gt;
  using namespace std;
  int* counter = new int[1024];
  void updateCounter(int position)
  {
      for (int j = 0; j &lt; 100000000; j++)
      {
          counter[position] = counter[position] + 8;
      }
  }
  int main() {
      time_t begin, end;
      begin = clock();
      thread t1(updateCounter, 1);
      thread t2(updateCounter, 2);
      thread t3(updateCounter, 3);
      thread t4(updateCounter, 4);
      t1.join();
      t2.join();
      t3.join();
      t4.join();
      end = clock();
      cout&lt;&lt;end-begin&lt;&lt;endl;  //1833
      begin = clock();
      thread t5(updateCounter, 16);
      thread t6(updateCounter, 32);
      thread t7(updateCounter, 48);
      thread t8(updateCounter, 64);
      t5.join();
      t6.join();
      t7.join();
      t8.join();
      end = clock();
      cout&lt;&lt;end-begin&lt;&lt;endl;   //358
  
  }
  </code></pre>
  <p>the first code block run about 1833 seconds,but the second which is almost same with the first one
  run about 358 seconds.Beg for an answer!Thank you!</p>