title: static storage with pthread functions
body: <p>I was practicing some multithreaded programs, but I could not figure the logic behind this output. </p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;pthread.h&gt;
  
  int print_message(void* ptr);
  
  int main()
  {
  pthread_t thread1,thread2;
  char *mesg1 = "Thread 1";
  char *mesg2 = "Thread 2";
  
  int iret1, iret2;
  
  pthread_create(&amp;thread1, NULL, print_message, (void *)mesg1);
  pthread_create(&amp;thread2, NULL, print_message, (void *)mesg2);
  
  pthread_join(thread1,(void*)&amp;iret1 );
  pthread_join(thread2, (void*)&amp;iret2);
  
  printf("Thread 1 return : %d\n", (int)iret1);
  printf("Thread 2 return : %d\n", (int)iret2);
  return 0;
  
  }
  
  int print_message(void *ptr)
   {
  char *mesg;
  static int i=0;
  mesg = (char *)ptr;
  printf("%s\n",mesg);
  i++;
  return ((void*)i);
  
  }
  </code></pre>
  
  <p>I was expecting the output</p>
  
  <pre><code>Thread 1
  Thread 2
  Thread 1 return : 1
  Thread 2 return : 2
  </code></pre>
  
  <p>but I am getting the output</p>
  
  <pre><code>Thread 1
  Thread 2
  Thread 1 return : 0
  Thread 2 return : 2
  </code></pre>
  
  <p>Could some please clarify this to me ? And please point if any errors in usage of pthread functions.</p>