Question: 1 / * WARNING: This code is buggy! * / 2 #include csapp.h 3 void * thread ( void * vargp ) ; 4
WARNING: This code is buggy!
#include "csapp.h
void threadvoid vargp;
int main
pthreadt tid;
pthreadcreate&tid, NULL, thread, NULL;
exit;
Thread routine
void threadvoid vargp
sleep;
printfHello world!
;
return NULL;
codeconchellobugc
Wondering if my answers for A and B are correct.
A The program in Figure has a bug. The thread is supposed to sleep for
second and then print a string. However, when we run it on our system,
nothing prints. Why?
My answer: Theres a bug because the Exit; function in line terminates the whole process, including all threads, before the thread gets a chance to run.
B You can fix this bug by replacing the exit function in line with one of two
different Pthreads function calls. Which ones?
My answer: You fix this by replacing Exit; with pthreadexitNULL; or with pthreadjointid NULL;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
