int threads = 5;
pthread_t * thread = malloc(sizeof(pthread_t)*threads);
for (i = 0; i < threads; i++){
int ret = pthread_create(&thread[i], NULL, &foobar_function, NULL);}
I’m not in a position to run the code right now. But I saw this as part of an online example and was a little confused by the total lack of square brackets. I’m not great with C.
So does this work for creating an array of threads?
Yes.
threadis pointing at a block of memory allocated bymallocthat is large enough to holdthreadspthread_tobjects.An array of
threadspthread_tobjects can be represented in exactly this way.