Semaphore :
- Semaphore is a variable which contains an integer value that is
used to solve the critical section problem
- It is a synchronization tool which is used to achieve process
synchronization in the multiprocessing environment.
- It contains two variables P and
V.
Properties of semaphore variables
- V called as signal operation always increments the semaphore
value and it is always successful on semaphore
- P called as wait operation always decrements the semaphore
value and it is successful until it becomes 0.
- The variable will always hold a nonnegative integer value.
- The two most common kinds of semaphores are counting semaphores
and binary semaphores.
- Counting semaphore can take non-negative integer values and
Binary semaphore can take the value 0 & 1. only
- They can be implemented using test operations and interrupts.
They can also be executed using file descriptors
Wait operation(P) :
- wait operation is denoted by variable P.
- wait operaiton decrements the semaphore value
- It is defined as follows.
wait(S)
{
while(S<=0)
S -- ;
}
Signal operation(V) :
- It is denoted using variable V
- It increments the semaphore value.
- It is defined as follows
signal(S)
{
while (S>=0);
S++ ;
}