ALL > Computer and Education > courses > university courses > undergraduate courses > Operating System > ZSTU class(2018-2019-1) > student homework > 2015329620091贺鸿 >
homework5 Version 0
👤 Author: by 1146715683qqcom 2018-10-22 07:36:55
wait(Semaphore S)
{
while S<=0
; //no operation
S--;
}

Definition of signal()
signal(S)
{
S++;
}

Let the initial value of a semaphore be 1, and say there are two concurrent processes P0 and P1 which are not supposed to perform operations of their critical section simultaneously.Now say P0 is in its critical section, so the Semaphore S must have value 0, now say P1 wants to enter its critical section so it executes wait(), and in wait() it continuously loops, now to exit from the loop the semaphore value must be incremented, but it may not be possible because according the source, wait() is an atomic operation and can't be interrupted and thus the process P0 can't call signal() in a single processor system.

When a task attempts to acquire a semaphore that is unavailable, the semaphore places the task onto a wait queue and puts the task to sleep.The processor is then free to execute other code.When the semaphore becomes available, one of the tasks on the wait queue is awakened so that it can then acquire the semaphore.

while S<=0 ; //no operation This doesn't mean that the processor running this code. The process/task is blocked until it gets the semaphore.

Please login to reply. Login

Reversion History

Loading...
No reversions found.