title: passing for loop index into pthread_create argument object in C
body: <p>I would like to pass my for loop's index into the pthread_create's argument through a wrapper object. However, the printed integer from the thread is incorrect.
  I expected the below code to print out, in no particular order.</p>
  
  <blockquote>
    <p>id is 0, id is 1, id is 2, id is 3,</p>
  </blockquote>
  
  <p>However it prints this instead and integer 1,3 is never passed into a thread</p>
  
  <blockquote>
    <p>id is 0, id is 0, id is 0, id is 2,</p>
  </blockquote>
  
  <pre><code>struct thread_arg {
   int id;
   void * a;
   void * b;
  }
  
  void *run(void *arg) {
   struct thread_arg * input = arg;
   int id = input-&gt;id;
   printf("id is %d, ", id)
  }
  
  int main(int argc, char **argv) {
   for(int i=0; i&lt;4; i++) {
    struct thread_arg arg;
    arg.id = i;
    arg.a = ...
    arg.b = ...
    pthread_create(&amp;thread[i], NULL, &amp;run, &amp;arg);
   }
  </code></pre>
  
  <p>}</p>