title: Thread Synchronization not getting expected output
body: <p>i am not getting any output but i am expecting output as <em>THREAD1 THREAD2</em> below is the code..</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;pthread.h&gt;
  
  using namespace std;
  
  void* fun(void *arg)
  {
     char *msg;
     msg = (char*)arg;
     cout&lt;&lt;msg&lt;&lt;endl;
  }
  
  int main()
  {
  
     pthread_t t1,t2;
  
     t1 = pthread_create(&amp;t1,NULL,fun,(void*)"THREAD1");
     t2 = pthread_create(&amp;t2,NULL,fun,(void*)"THREAD2");
  
     pthread_join(t1,NULL);
     pthread_join(t2,NULL);
    // sleep (2);
     return 0;
  }
  </code></pre>
  
  <p>I changed above code to </p>
  
  <pre><code>   pthread_create(&amp;t1,NULL,fun,(void*)"THREAD1");
     pthread_create(&amp;t2,NULL,fun,(void*)"THREAD2");
  </code></pre>
  
  <p>Now i am getting <em>THREAD2 THREAD1</em> but i need <em>THREAD1 THREAD2</em></p>
  
  <p>Now i changed my code to ></p>
  
  <pre><code>pthread_create(&amp;t1,NULL,fun,(void*)"THREAD1");
  pthread_join(t1,NULL);    
  
  pthread_create(&amp;t2,NULL,fun,(void*)"THREAD2");
  pthread_join(t2,NULL);
  </code></pre>
  
  <p>Now my result is Proper as <em>THREAD1 THREAD2</em></p>