Answered step by step
Verified Expert Solution
Question
1 Approved Answer
i want to fix the solution and provide an explanation why the pthread_join is not working as intended? #include /* standard I/O routines */ #include
i want to fix the solution and provide an explanation why the pthread_join is not working as intended? #include/* standard I/O routines */ #include /* pthread functions and data structures */ void* PrintHello(void* data) { pthread_t tid = (pthread_t)data; /* data received by thread */ pthread_join(tid, NULL); /* wait for thread tid */ printf("Hello from new thread %u - got %u ", pthread_self(), data); pthread_exit(NULL); /* terminate the thread */ } /* like any C program, program's execution begins in main */ int main(int argc, char* argv[]) { int rc; /* return value */ pthread_t thread_id; /* thread's ID (just an integer) */ int tid; tid = pthread_self(); rc = pthread_create(&thread_id, NULL, PrintHello, (void*)tid); if(rc) /* could not create thread */ { printf(" ERROR: return code from pthread_create is %d ", rc); exit(1); } sleep(1); printf(" Created new thread (%u) ... ", thread_id); pthread_exit(NULL); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started