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
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