Question: The following Pthread C program is intended to synchronize parent and child thread execution to produce the following output. parent: begin child parent: end However,

 The following Pthread C program is intended to synchronize parent andchild thread execution to produce the following output. parent: begin child parent:

The following Pthread C program is intended to synchronize parent and child thread execution to produce the following output. parent: begin child parent: end However, when this program executes, the parent thread occasionally freezes prior to print "parent: end". - First, explain why this happens. - Second, copy the program source to the answer box and fix the problem(s). If you need, you can refer to Pthread reference link. \#include pthread.h \#include stdio.h \#include stdlib.h pthread_mutex_t m= PTHREAD_MUTEX_INITIALIZER; pthread_cond_t c= PTHREAD_COND_INITIALIZER; void thr_exit() \{ pthread_mutex_lock(\&m); pthread_cond_signal(\&c); pthread_mutex_unlock(\&m); \} void *child(void *arg) \{ printf("child "); thr_exit(); \} void thr_join() \{ pthread_mutex_lock(\&m) pthread_cond_wait (&c,&m); pthread_mutex_unlock(\&m); \} int main(int argc, char *argv[]) \{ printf("parent: begin "); pthread_t p; pthread_create(\&p, NULL, child, NULL); thr_join(); printf("parent: end "); return 0 ; \}

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!