Sunday, 3 June 2018

What is Semaphore Algorithm in Operating System

What is Semaphore Algorithm in Operating System:

It is a software tool to solve the complex critical Problem. it has two atomic operation.

  1. Wait
  2. Signal

This algorithm is suitable for solving of complex synchronization problem.

" There is a software tool to solve complex synchronization problem called Semaphore."

Semaphore used integer digit to solve the problem ( S= 0  or  1  ).
A part from initialization of integer variable .semaphore also use two atomic operation wait  ( ) and signal ( ).

The classical definition of wait ( ) and signal ( ) operation is...

wait ( S ) : if  S<= 0                         do no Operation
                       S--;

Signal ( S ) :    S ++ ;

   To solve the critical section problem for n problem. a shared data item mutex is used.

Semaphore mutex ; ( / initially 1 )

for Process Pi
do
 {
     wait ( mutex ) ;
    < C.S >
   signal ( mutex ) ;
< R.S >
}

wait ( S )

{

if ( S<= 0 )  do no operation

S--
}
signal ( S )
{
S++ ;
}

There are two types of Semaphore are used.


1- Counting Semaphore:

The range of counting semaphore is vary form any of the non negative/ Positive number to indefinite.

2- Binary Semaphore:

In binary semaphore the value of S is in between 0  and 1 .


No comments:

Post a comment

Popular Posts