title: Incompatible pointer type with pthread_create (C)
body: <p>I'm working on a personal project that uses multi threading to split an array, search for a target, and return the number of matches. I've got one bug and a few errors with my early code.</p>
  
  <p>Errors...</p>
  
  <pre><code>main.c:117:10: warning: passing argument 1 of 'pthread_create' from incompatible pointer type [enabled by default]
  
  In file included from main.c:5:0: /usr/include/pthread.h:225:12: note: expected 'pthread_t * restrict' but argument is of type 'pthread_t **'
  </code></pre>
  
  <p>I'm very new to POSIX and have no clue what's wrong here.</p>
  
  <p>Bug...</p>
  
  <p>My big loop that is supposed to loop as long as index &lt; totalElems only loops once. It goes into the small loop and drops out of both instead of looping more. I'm not sure why this is.</p>
  
  <p>Header file...</p>
  
  <pre><code>#ifndef COUNT_ARRAY_H
  #define COUNT_ARRAY_H
  
  
  // structure declarations
  typedef struct
  {
   int     threadNum;
   int     *array;
   int     first;
   int     last;
   int     target;
   int     numFound;
  
  } ThreadInfo;
  
  
  // function prototypes
  void*   ThreadFunc(void  *vptr);
  
  
  #endif  // COUNT_ARRAY_H
  </code></pre>
  
  <p>.
  .</p>
  
  <p>Main.c file....</p>
  
  <pre><code>#include    &lt;pthread.h&gt;
  #include    &lt;stdio.h&gt;
  #include    &lt;stdlib.h&gt;
  #include    "count_array.h"
  
  int     main(void)
  {
   auto    int                 numSegs;
   auto    int                 numSegElems;
   auto    int                 maxRand;
   auto    int                 target;
   auto    int                 totalElems;
   auto    int                 totalFound = 0;
   auto    ThreadInfo          *infoPtr;
   auto    pthread_t           *threadHandles;
   auto    int                 index = 0;
   auto    int                 first;
   auto    int                 last;
   auto    int                 threadNum = 0;
  
  //get primary info from user...
  printf(" Please enter the total number of elements? ");
  scanf("%d", &amp;totalElems);
  
  printf(" Please enter the maximum random value: ");
  scanf("%d", &amp;maxRand);
  
  printf(" Please enter the number of segments (1 to 15857): ");
  scanf("%d", &amp;numSegs);
  
   if(numSegs &gt; 15857)
     {
      puts(" Too many segments for machine!");
      exit(EXIT_FAILURE);
     }
  
  numSegElems = totalElems/numSegs;
  
  // configure the array to work with
  // declare array here...
  
  auto int myArray[totalElems];
  
  //and fill array here
  for(; index &lt; totalElems; index++)
     {
      // % rand() and maxRand to get good range and
      //not go beyond users max number
      myArray[index] = (rand() % maxRand);
  
      //test printf...ignore if still here at 5/18/17 or later
       printf(" %d \n", myArray[index]);
     }
  
  // get the target value to look for
   printf(" Please enter the target value: ");
   scanf("%d",&amp;target);
  
  // display initial information
  printf("*** Begin search: target = %d, # elements = %d, # segments = %d, "
                                              "# segment elements = %d\n"
                                                              , target
                                                              , totalElems
                                                              , numSegs
                                                              , numSegElems);
  
  
  // initialize the array first/last indexes into the integer array
  // &gt;&gt;&gt;50 elems total/5 = 10 threads total and 5 elems in each thread&lt;&lt;&lt;
    for(index = 0; index &lt; totalElems; index++)
       {
  
        first = myArray[0];
  
        if(index == numSegElems)
          {
  
           puts(" in if ");
           last = myArray[index];
  
           printf(" %d \n", index);
  
  
  // allocate an array to store the thread handles
  
           auto int arraySeg[numSegElems];
  
   // loop and create threads (# of segments)
  
      // allocate a thread info structure from the heap
      //using malloc
  
           infoPtr = malloc(sizeof(ThreadInfo));
           if(NULL == infoPtr)
             {
              fprintf(stderr, "Unable to allocate ThreadInfo struct for "
                             "thread #%d\n", threadNum);
  
              continue;
             }
      // store the information in the allocated structure
           infoPtr-&gt;target = target;
           infoPtr-&gt;threadNum = threadNum;
           infoPtr-&gt;first = first;
           infoPtr-&gt;last = last;
           infoPtr-&gt;array = arraySeg;
  
      // create the secondary thread, passing the thread info
         if(pthread_create(&amp;threadHandles, NULL, ThreadFunc, &amp;infoPtr))
           {
            fprintf(stderr, "Error: failed to create thread #%d\n", 
            threadNum);
            continue;
           }
  
      // update the first/last array indexes for the next thread
      //set to zero again??
  
        }//end small loop to make individual threads
  
      //increment thread #
         ++threadNum;
  
      }//end big loop
        // loop and join the threads to fetch each thread's results
  
      // join with the next thread
  
          // get the total number of matches from the thread's infoPtr
          // and display a message
  
          // release the infoPtr structure back to the heap
  
  
  // display the final results
  
  // release heap memory
  
  
     return 0;
  
  }  // end of "main"
  </code></pre>
  
  <p>I've done a smaller project like this before, but I'm not seeing what's wrong here. I need to pass infoPtr and use the members in ThreadFunc. I'm doing this like my other programs exactly, but it's not working. I've tried searching the site and google, but maybe I can't figure it out because it's too specific? Also, removing the &amp; doesn't help. Any help would be appreciated!</p>