Atomic Operations in Semaphore
Here we will discuss the two atomic operations wait and signal as follows.
Operation-1 Wait(S)
According to the value of S.V. if it is non-zero, decrement its value, and process p can continue its execution and if it is zero, process p is added to the set component, and the state of the process p becomes blocked in this case process p is said to have been blocked on the semaphore.
Algorithm
if(S.V > 0) { S.V. = S.V -1 } else{ S.L. = S.L. U p p.state = blocked }
Operation-2 Signal(S)
According to the value of S.L., if it is empty increment the value of the integer and if it is non-empty unblock q an arbitrary of the set of processes blocked o S.L. and change the status of p to ready.
Algorithm
if(S.L. == φ){ S.V. = S.V.+1 } else{ Let q be some process in S.L. S S.L. = S.L. - {q} q.state = ready }
Semaphores and its types
Semaphores are compound data types with two fields one is a Non-negative integer S.V. and the second is a set of processes in a queue S.L. It is used to solve critical section problems, and by using two atomic operations, it will be solved. In this, wait and signal that is used for process synchronization.