Question: The following is a solution to design and implement a General Semaphore . Is Line 10 while(!s.hold); necessary? Please use one example to explain. Implementing

The following is a solution to design and implement a General Semaphore. Is Line 10 while(!s.hold); necessary? Please use one example to explain.

Implementing the General Semaphore

struct semaphore {

int value = ;

boolean mutex = FALSE;

boolean hold = TRUE;

};

shared struct semaphore s;

P(struct semaphore s) {

L1 while(TS(s.mutex)) ;

L2 s.value--;

L3 if(s.value < 0) {

L4 s.mutex = FALSE;

L5 while(TS(s.hold)) ;

}

else

L6 s.mutex = FALSE;

}

V(struct semaphore s) {

L7 while(TS(s.mutex)) ;

L8 s.value++;

L9 if(s.value <= 0) {

L10 while(!s.hold) ;

L11 s.hold = FALSE;

}

L12 s.mutex = FALSE;

}

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!