title: pthreads not working correctly
body: <p>I have the following code which was simplified to show only the relevant part.</p>
  
  <p>My problem is that on one machine it shows correctly the thread number and all the other values but when I run it on other machines it shows the same values for all the threads created.</p>
  
  <p>I compile it with -lpthread, I even tried to compile it statically but same results.</p>
  
  <p>Why does it work correctly on one machine and on others not? Is it some coding mistake or do I have to change libraries upon compilation? 
  I am stuck. Thanks!</p>
  
  <pre><code>    pthread_mutex_t word_list;
      struct words_list {
          char myword[20];
          struct words_list * next;
      };
      struct arg_struct {
          char *myword;
          int t;
      };
      char myword[20];
      struct words_list * first_word = NULL;
              //the loading data into struct code is missing from here
      struct words_list * curr_word = first_word;
      pthread_mutex_init(&amp;word_list,NULL);        
      int ex = 0;
      while(curr_word != NULL)
      {
          struct arg_struct args;
          int ret = -1;
          for(i = 0 ; i &lt; max_thread; i++)
          {
              pthread_mutex_lock(&amp;word_list);
              strncpy(myword,curr_word-&gt;myword,sizeof(myword) - 1);
              pthread_mutex_unlock(&amp;word_list);
              args.myword = myword;
              args.t = i;
  
              //start threads
              if(pthread_create(&amp;thread_id[i],NULL,&amp;do_repl,&amp;args) != 0)
              {
                  i--;
                  fprintf(stderr,RED "\nError in creating thread\n" NONE);
              }
              else
              {
                  pthread_mutex_lock(&amp;word_list);
                  if(curr_word-&gt;next == NULL)
                      ex = 1;
                  else
                      curr_word = curr_word-&gt;next;
                  pthread_mutex_unlock(&amp;word_list);
              }
          }//end threads creating
  
          for(i = 0 ; i &lt; max_thread; i++)
          {
              void *join_result;
              if(pthread_join(thread_id[i],&amp;join_result) != 0)
                  fprintf(stderr,RED "\nError in joining thread\n" NONE);
              else
              {
                  ret = *(int *)join_result;
                  free(join_result);
                  if((ret == 1)
                  {
                      ex = 1;
                      break;
                  }
              }
          }//end threads joining
          if (ex == 1)
              break;
      }//end while
  
  
  
  
  
  
      void* do_repl(void *arguments)
      {
          int *res = malloc(sizeof(int));
          struct arg_struct *args = arguments;
          char *word = args-&gt;word;
          int t = args-&gt;t;
          fprintf(stderr,"(%d) word: %s\n",t,word);
          *res = 0;
          return res;
      }
  </code></pre>