I have this piece of code shown below.
Where nrthr stands for number of threads and is entered by the user. I always want my "main program" to call testFunc once, so if the user enter nrthr to be number 3 I then want to create 2 new threads. So my question is... how can I just call testFunc before the while loop?
int threadCount = 0;
...
// Call testFunc here
while(threadCount < nrthr - 1) {
fprintf(stderr, "Created thread: %d\n", threadCount);
if(pthread_create(&(tid[threadCount++]), NULL, testFunc, args) != 0)
fprintf(stderr, "Can't create thread\n");
}
void *testFunc(void *arg)
{
...
}