A semaphore is variable with integer value that is updated through 2 standard operations which are atomic :
(1) P: wait () operation
and
(2) V: signal () operation.
Lets say Semaphore variable is Sm
wait(Sm) {
while Sm<= 0 ; //No-operation, keep in while loop if condition true, next line will not execute
Sm - - ; //executed if while loop is not satisfied
}
signal(Sm) {
Sm + +;
}
As both functions are atomic whole wait() and signal() function must be executed without interruption. This means the while condition check and the Sm - - operation will be executed without break or interruption. Variable Sm can only be accessed by only one function either wait() or signal() at a time.
(1) P: wait () operation
and
(2) V: signal () operation.
Lets say Semaphore variable is Sm
wait(Sm) {
while Sm<= 0 ; //No-operation, keep in while loop if condition true, next line will not execute
Sm - - ; //executed if while loop is not satisfied
}
signal(Sm) {
Sm + +;
}
As both functions are atomic whole wait() and signal() function must be executed without interruption. This means the while condition check and the Sm - - operation will be executed without break or interruption. Variable Sm can only be accessed by only one function either wait() or signal() at a time.
No comments:
Post a Comment