title: pthread_join() causing segmentation fault
body: <p>I'm working on understanding threads and have run up against this segmentation fault that I can't seem to correct.  I have narrowed down the error to the <code>pthread_join()</code> function, but can't seem to go any further.  My understanding is that the for loop needs to be the same as the one for the <code>pthread_create()</code> and that the variable that is passed in is the dereferenced pointer being passed into the <code>pthread_exit()</code> function. Any direction would be greatly appreciated. </p>
  
  <pre><code>#include &lt;pthread.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;math.h&gt;
  
  //void *runner(void *param);
  
  void *pFactor(void *param)
  {
          int *pFArray = malloc(sizeof(int) *32);
          int myNum = atoi(param);
          int count = 0;
  
          printf("I'm getting here");
  
          while (myNum % 2 == 0)
          {
                  pFArray[count] = 2;
                  myNum = myNum/2;
                  count++;
          }
  
          for (int i = 3; i &lt; sqrt(myNum); i += 2)
          {
                  while (myNum % i == 0)
                  {
                          pFArray[count] = i;
                          myNum = myNum/i;
                          count++;
                  }
          }
  
          if (myNum &gt; 2)
          {
                  pFArray[count] = myNum;
          }
  
          //int *arrPtr = (int*) malloc(10);
          //arrPtr = pFArray;
          //return (void *) arrPtr;
          //return fprint("I made it to the end of the pFactor function")
          pthread_exit(pFArray);
  
  }
  
  int main(int argc, char *argv[])
  {
          pthread_t tid[argc];
          pthread_attr_t attr;
  
          if (argc == 0)
          {
                  fprintf(stderr, "usage: a.out &lt;integer value&gt;\n");
                  return -1;
          }
          if (argc &lt; 0)
          {
                  fprintf(stderr, "%d must be &gt;= 0\n", atoi(argv[1]));
                  return -1;
          }
  
          /* Get the default attributes */
          pthread_attr_init(&amp;attr);
          /* Create the thread */
          for (int i = 1; i &lt; argc; i++)
          {
                  tid[i] = i;
                  pthread_create(&amp;tid[i], &amp;attr, pFactor, &amp;argv[i]);
                  printf("still working\n");
          }
          printf("still working\n");
          /* Wait for the thread to exit */
          for (int i = 1; i &lt; argc; i++)
          {
                  tid[i] = i;
                  void *my_Ptr;
                  printf("still working 1\n");
                  pthread_join(tid[i], &amp;my_Ptr);
                  printf("still working 2\n");
                  for (;;)
                  {
                          printf("%d", atoi(argv[i]));
                          printf(": %d",((int*) my_Ptr)[i-1]);
                  }
                  //printf("%d", atoi(argv[i]));
                  //printf(": %d",((int*) my_Ptr)[i-1]);
          } /*This is where you want to pass in the sum variable*/
  }
  </code></pre>