Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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