Question: Consider the following code snippet: #define MACHINE _ CAPACITY 6 4 sem _ t mutex, slots _ filled, slots _ empty; struct machine { int
Consider the following code snippet:
#define MACHINECAPACITY
semt mutex, slotsfilled, slotsempty;
struct machine int nitems; ;
double sleeptime return double randdouble RANDMAX;
void producerfnvoid args
int cokes;
struct machine curmachine struct machine args;
while
semwait&slotsempty;
semwait&mutex;
cokes curmachinenitems;
curmachinenitems ;
printfProducer enqueue cokes d d
cokes, curmachinenitems;
sempost&mutex;
sempost&slotsfilled;
sleepsleeptime;
void consumerfnvoid args
int cokes;
struct machine curmachine struct machine args;
while
semwait&slotsfilled;
semwait&mutex;
cokes curmachinenitems;
curmachinenitems ;
printfConsumer dequeue cokes d d
cokes, curmachinenitems;
sempost&mutex;
sempost&slotsempty;
sleepsleeptime;
int mainvoid
struct machine cokemachine nitems ;
srand timeNULL;
seminit&mutex, ;
seminit&slotsempty, MACHINECAPACITY;
seminit&slotsfilled, ;
pthreadt producer, consumer;
pthreadcreate&producer, NULL, producerfnvoid &cokemachine;
pthreadcreate&consumer, NULL, consumerfnvoid &cokemachine;
pthreadjoinproducer NULL;
pthreadjoinconsumer NULL;
return ; code only reaches here if the machine is broken
Which of the following statements is false?
Group of answer choices
Removing slotsfilled and slotsempty semaphores causes the datarace problem
In the producerfn swapping sempost&slotsfilled and sempost&mutex code lines causes deadlock.
In the producerfn swapping semwait&mutex and semwait&slotsempty code lines can cause deadlock problem.
This code runs without datarace or deadlock problems
Removing mutex semaphore causes the datarace problem
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
