title: Not sure if I need a mutex or not
body: <p>I'm new to concurrent programming so be nice. I have a basic sequential program (which is for homework) and I'm attempting to turn it into a multithreaded program. I'm not sure if I need a lock for my second shared variable. The threads should modify my variable but never read them. The only time count should be read is after the loop which spawns all of my threads has finished distributing keys.</p>
  
  <pre><code>#define ARRAYSIZE 50000
  
  #include &lt;pthread.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;sys/time.h&gt; 
  
  void binary_search(int *array, int key, int min, int max); 
  
  int count = 0; // count of intersections
  int l_array[ARRAYSIZE * 2]; //array to check for intersection
  
  int main(void)
  {
      int r_array[ARRAYSIZE]; //array of keys
      int ix = 0;
  
      struct timeval start, stop;
      double elapsed;
  
      for(ix = 0; ix &lt; ARRAYSIZE; ix++)
      {
          r_array[ix] = ix;
      }
      for(ix = 0; ix &lt; ARRAYSIZE * 2; ix++)
      {
          l_array[ix] = ix + 500;
      }
  
      gettimeofday(&amp;start, NULL);
  
      for(ix = 0; ix &lt; ARRAYSIZE; ix++)
      {
          //this is where I will spawn off separate threads
          binary_search(l_array, r_array[ix], 0, ARRAYSIZE * 2);
      }
  
      //wait for all threads to finish computation, then proceed.
  
      fprintf(stderr, "%d\n", count);
  
      gettimeofday(&amp;stop, NULL);
      elapsed = ((stop.tv_sec - start.tv_sec) * 1000000+(stop.tv_usec-start.tv_usec))/1000000.0;
      printf("time taken is %f seconds\n", elapsed);
      return 0;
  }
  
  void binary_search(int *array, int key, int min, int max)
  {
      int mid = 0;
      if (max &lt; min) return;
      else
      {
        mid = (min + max) / 2;
        if (array[mid] &gt; key) return binary_search(array, key, min, mid - 1);
        else if (array[mid] &lt; key) return binary_search(array, key, mid + 1, max);
        else 
        {
            //this is where I'm not sure if I need a lock or not
            count++;
            return;
        }
      }
  }
  </code></pre>