title: passing struct to pthread as an argument
body: <p>Ok I am trying to pass pair of numbers through <code>struct</code> to <code>pthread_create</code> function in <code>pthread</code>. But the numbers i am passing and numbers i am getting when the function is called are different and random</p>
  
  <p>Here is the <code>struct</code></p>
  
  <pre><code>struct Pairs {
      long i,j;
  };
  </code></pre>
  
  <p>And inside main</p>
  
  <pre><code>void main()
  {
      long thread_cmp_count = (long)n*(n-1)/2;
      long t,index = 0;
      struct Pairs *pair;
      pair = malloc(sizeof(struct Pairs));
  
      cmp_thread = malloc(thread_cmp_count*sizeof(pthread_t));
      for(thread = 0;(thread &lt; thread_cmp_count); thread++){
          for(t = thread+1; t &lt; n; t++){
              (*pair).i = thread;
              (*pair).j = t;
              pthread_create(&amp;cmp_thread[index++], NULL, Compare, (void*) pair);
  
          }
      }
  
      for(thread= 0;(thread&lt;thread_cmp_count); thread++){
          pthread_join(cmp_thread[thread], NULL);
      }
  
      free(cmp_thread);
  }
  </code></pre>
  
  <p>And function Compare</p>
  
  <pre><code>void* Compare(void* pair){
      struct Pairs *my_pair = (struct Pairs*)pair;
      printf("\nThread %ld, %ld", (*my_pair).i, (*my_pair).j);
      return NULL;
  }
  </code></pre>
  
  <p>Number I am getting and it is also random. </p>
  
  <pre><code>Thread 0,2
  Thread 1,2
  Thread 2,3
  Thread 2,3
  Thread 2,3
  Thread 2,3
  </code></pre>
  
  <p>am i passing the <code>struct</code> wrong ?</p>