title: C++ Multithreaded prime counter between specified range
body: <pre><code>#include &lt;math.h&gt;
  #include &lt;sstream&gt;
  #include &lt;iostream&gt;
  #include &lt;mutex&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;chrono&gt;
  #include &lt;thread&gt;
  
  bool isPrime(int number) {
      int i;
  
      for (i = 2; i &lt; number; i++) {
          if (number % i == 0) {
              return false;
          }
      }
  
      return true;
  }
  
  std::mutex myMutex;
  
  int pCnt = 0;
  
  int icounter = 0;
  
  int limit = 0;
  
  
  int getNext() {
      std::lock_guard&lt;std::mutex&gt; guard(myMutex);
      icounter++;
      return icounter;
  }
  
  void primeCnt() {
      std::lock_guard&lt;std::mutex&gt; guard(myMutex);
      pCnt++;
  }
  
  void primes() {
      while (getNext() &lt;= limit)
          if (isPrime(icounter))
              primeCnt();
  }
  
  int main(int argc, char *argv[]) {
      std::stringstream ss(argv[2]);
      int tCount;
      ss &gt;&gt; tCount;
  
      std::stringstream ss1(argv[4]);
      int lim;
      ss1 &gt;&gt; lim;
  
      limit = lim;
  
      auto t1 = std::chrono::high_resolution_clock::now();
  
      std::thread *arr;
      arr = new std::thread[tCount];
  
      for (int i = 0; i &lt; tCount; i++)
          arr[i] = std::thread(primes);
  
      for (int i = 0; i &lt; tCount; i++)
          arr[i].join();
  
      auto t2 = std::chrono::high_resolution_clock::now();
  
      std::cout &lt;&lt; "Primes: " &lt;&lt; pCnt &lt;&lt; std::endl;
      std::cout &lt;&lt; "Program took: " &lt;&lt; std::chrono::duration_cast&lt;std::chrono::milliseconds&gt;(t2 - t1).count() &lt;&lt;
      " milliseconds" &lt;&lt; std::endl;
      return 0;
  }
  </code></pre>
  
  <p>Hello , im trying to find the amount of prime numbers between the user specified range, i.e., 1-1000000 with a user specified amount of threads to speed up the process, however, it seems to take the same amount of time for any amount of threads compared to one thread. Im not sure if its supposed to be that way or if theres a mistake in my code. thank you in advance!</p>