+1 vote
18 views

1 Answer

+1 vote
by (user.guest)
selected by (user.guest)
 
Best answer

Semaphores:

For the solution to the critical section problem one synchronization tool is used which is known as semaphores. A semaphore ‘S’ is an integer variable which is accessed through two standard operations such as wait and signal. These operations were originally termed ‘P’ (for wait means to test) and ‘V’ (for single means to increment). The classical definition of wait is  

 Wait (S)

 {

 While (S <= 0)

 {

 Test;

 }

 S--;

 }

The classical definition of the signal is

 Signal (S)

 {

 S++;

 }

In case of wait the test condition is executed with interruption and the decrement is executed without interruption.  

Binary Semaphore:

A binary semaphore is a semaphore with an integer value which can range between 0 and 1.

Let ‘S’ be a counting semaphore. To implement the binary semaphore we need following the structure of data.  

Binary Semaphores S1 , S2 ;  

int C;

Initially S1 = 1, S2 = 0 and the value of C is set to the initial value of the counting semaphore ‘S’.  

Then the wait operation of the binary semaphore can be implemented as follows.

Wait (S1

)

C--;

if (C < 0)

{

 Signal (S1

);

 Wait (S2

);

}Signal (S1

);

The signal operation of the binary semaphore can be implemented as follows:

Wait (S1 );  

C++;

if (C <=0)

Signal (S2 );  

LElse

Signal (S1

);

Related questions

+1 vote
1 answer
+1 vote
1 answer
+1 vote
1 answer
+1 vote
1 answer
Welcome to CPEN Talk
Solution-oriented students of computer engineering on one platform to get you that

ONE SOLUTION

...