BuzzTalk
Would you like to react to this message? Create an account in a few clicks or log in to continue.

CONCEPT OF SEMAPHORES

Go down

CONCEPT OF SEMAPHORES Empty CONCEPT OF SEMAPHORES

Post  saurabh saxena Mon Nov 17, 2008 1:36 pm

Basically,semaohore is an integer variable.apart from initializing we can use two standard atomic operations like wait and signal.
In latin wait refers to test hence we use wait to test and signal to increment.Now these two processes are mutually exclusive that is if the wait operation is going on then signal operation can't occur and similarly if signal operation is going on then wait operation can't take place.This semaphore concept was invented by Djikstra.actually we use this concept in synchronization problems like dining philosophers problem,producer-consumer problem,sleeping-barber problem..etc.
The value of semaphore is always equal to the no. of resources free at that moment.if there is only one resource free then we use the specisl semaphore known as binary semaphore.This binary semaphore takes only two values 0 or 1.if we write the coding of the two atomic operations which are executed on the semaphores are as:-

typedef int semaphore;
semaphore sem;
wait(sem) //definition of the wait operation
{
if (sem <= 0)
{
sem--;
}
}

signal(sem)
{
sem++; //definition of the signal operation
}
we use this definition of semaphores in process and resource synchronisation.
saurabh saxena
saurabh saxena

Number of posts : 19
Age : 38
Location : pune
Registration date : 2008-08-22

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum