I am working on a code with multiple number of threads and I want to print the time it took for me to complete task I assigned the i-th thread to do. Meaning I want to print the time each thread took to be done with the doSomeThing function
int main(int argc, char *argv[]){
// ...
i=0;
while (i < NumberOfThreads){
check = pthread_create(&(id_arr[i]), NULL, &doSomeThing, &data);
i++;
}
// ...
}
void* doSomeThing(void *arg){
// ...
}
if I add gettimeofday(&thread_start, NULL)
before the pthread_create
and then add gettimeofday(&thread_end, NULL)
after the pthread_create
, will I be actually measuring the time each thread took or just the time the main took? And if I put the gettimeofday
inside the doSomething
function wouldn't they create race-conditions?
If you have any idea on how to measure the time per thread please let me know, thank you.