I'm working in C, and I'm trying to pass in a pointer to an array that will hold my thread ids, but I cannot seem to get my types to match. What am I not understanding about passing pointers in C?
This is my function:
int createThreads(int numThreads, pthread_t **tidarray) {
pthread_t *tids = *tidarray;
int i;
for (i = 0; i < numThreads; i++) {
pthread_create(tids + i, NULL, someFunction, NULL);
}
return 0;
}
And this is my call:
pthread_t tids[numThreads];
createThreads(5, &tids);
When I compile this, I get a warning: Passing argument 2 of 'createThreads' from incompatible pointer type, and Note: expected 'pthread_t **' but argument is of type 'pthread_t (*) [(long unsigned int)(numThreads)]'
pthread_t *, not a**. - user253751tidarrayis not an array pointer, it's a pointer to a pointer. An array pointer would bepthread_t (*tidarray)[numThreads], as suggested by the error message. - emlai