void createThreads(int k){
struct threadData threadData[k];
int numThreads = k;
int i = 0;
int err = 0;
pthread_t *threads = static_cast<pthread_t*>(malloc(sizeof(pthread_t) * numThreads));
for(i = 0;i<numThreads;i++){
threadData[i].thread_id = i;
threadData[i].startIndex = ((N/k)*i);
threadData[i].stopIndex = ((N/k)*(i+1));
err = pthread_create(&threads[i], NULL, foo, (void *)&threadData[i]);
if(err != 0){
printf("error creating thread\n");
}
}
}
Here, N and k are integers where the remainder of N/k is guaranteed to be 0. including createThreads(numThreads); in main will cause my program to seg fault and commenting it out will take care of this however any printf debug statements I put into createThreads (even on the first line inside the function) will not show so I am pretty confused as to how to debug this. All help is appreciated.
struct threadData threadData[k];This is not legal C++. You can't create an array using a variable as the number of entries.