2019529628011_ENOCH KWATEH DONGBO_Homework#6 Version 0 |
|
đ¤ Author: by enochdongbogmailcom 2021-12-09 02:23:38 |
Question: Propose your problem which may encounter process synchronization, and use a semaphore to solve the problem.
Solution:
My problem: Whenever a process is constantly checking semaphore value while waiting (see while(s==0) in the P operation) and wasting CPU cycles, we can take the following train of thought to avoid this situation:
P(Semaphore s)
{
S=S - 1;
if (s<0){
block();
}
}
V(Semaphore s)
{
S = S + 1;
if(s > = 0){
wakeup (p);
}
}