Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Figure 5.6 /* program mutualexclusion*/ const int n-/* number of processes */ semaphore s - 1; void P(int i) while (true) semWait (s)i /*critical section*
Figure 5.6
/* program mutualexclusion*/ const int n-/* number of processes */ semaphore s - 1; void P(int i) while (true) semWait (s)i /*critical section* semSignal(s); /* remainder; void main() parbegin (P(1), P(2), . . ., P(n)); Figure 5.6 Mutual Exclusion Using Semaphores 4 (5 points) Consider the following definition of semaphores: void semWait(s) if (s.count > 0)5 s.count--; else { place this process in s.queue; block; void semSignal (s) if (there is at least one process blocked orn semaphore s) f remove a process P from s.queue; place process P on ready list; else s.count+ Compare this set of definitions with that of Figure 5.6. Note one difference: With the preceding definition, a semaphore can never take on a negative value. Is there any difference in the effect of the two sets of definitions when used in programs? That is, could you substitute one set for the other without altering the meaning of the program? /* program mutualexclusion*/ const int n-/* number of processes */ semaphore s - 1; void P(int i) while (true) semWait (s)i /*critical section* semSignal(s); /* remainder; void main() parbegin (P(1), P(2), . . ., P(n)); Figure 5.6 Mutual Exclusion Using Semaphores 4 (5 points) Consider the following definition of semaphores: void semWait(s) if (s.count > 0)5 s.count--; else { place this process in s.queue; block; void semSignal (s) if (there is at least one process blocked orn semaphore s) f remove a process P from s.queue; place process P on ready list; else s.count+ Compare this set of definitions with that of Figure 5.6. Note one difference: With the preceding definition, a semaphore can never take on a negative value. Is there any difference in the effect of the two sets of definitions when used in programs? That is, could you substitute one set for the other without altering the meaning of the programStep 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