title: pthreads and concurrency
body: <p>I have the following code:</p>
  
  <pre><code>#include &lt;pthread.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  #define LOOPS 10000
  
  void *run(void *arg)
  {
      int id = strtol(arg,NULL,0);
      int i;
      for(i=0; i&lt;LOOPS; i++)
      {
          printf("In %d.\n",id);
      }
  }
  
  int main()
  {
      pthread_t p1,p2;
      void *res;
  
      pthread_create(&amp;p1,NULL,run,"1");
      pthread_create(&amp;p2,NULL,run,"2");
      pthread_join(p1,&amp;res);
      pthread_join(p2,&amp;res);
      return 0;
  }
  </code></pre>
  
  <p>When I run this, either the string "In 1" displays 10000 times consecutively then "In 2" displays 10000 times consecutively or vice versa. Shouldn't the strings be alternating and not displaying consecutively as they are here?</p>