Question: The following program has a bug. The thread is supposed to sleep for 1 second and then print a string. However, when it is run,

The following program has a bug. The thread is supposed to sleep for 1 second and then print a string. However, when it is run, nothing prints. Why?

You can fix this bug by replacing a function in the main thread with one of two different pthread function calls. Which one is it?

#include

#include

#include

void *thread(void* arg);

int main(){

pthread_t tid;

pthread_create(&tid, NULL, thread, NULL);

exit(0);

}

void* thread(void* arg) {

sleep(1);

printf("Hi there! ");

return NULL;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!