Page 110 - DCAP403_Operating System
P. 110
Unit 6: Process Synchronization
V (mutex) Notes
V (full);
Consumer ( )
WHILE (true)
P (full)
P (mutex);
remove-Item ( );
V (mutex);
V (empty);
consume-Item (Item)
A semaphore is hardware or a software tag variable whose value indicates the status of a common
resource. Its purpose is to lock the resource being used. A process which needs the resource
will check the semaphore for determining the status of the resource followed by the decision
for proceeding. In multitasking operating systems, the activities are synchronized by using the
semaphore techniques.
Semaphore is a machanism to resolve resources conflicts by tallying resource seekers what is the
state of sought resources, achieving a mutual exclusive access to resources. Often semaphore
operates as a type of mutual exclusive counters (such as mutexes) where it holds a number of
access keys to the resources. Process that seeks the resources must obtain one of those access
keys, one of semaphores, before it proceeds further to utilize the resource. If there is no more such
a key available to the process, it has to wait for the current resource user to release the key.
A semaphore could have the value 0,indicating that no wakeups were saved, or some positive
values if one or more wakeups were pending.
A semaphore s is an integer variable that apart from initialization, is accesssed only through two
standard atomic operations, wait and signal. these operations were orignially termed p(for wait
to test) and v(for signal to increment).
The classical defination of wait in psedocode is:
wait(s)
{
while(s<=0)
;// no-op
s--;
}
The classical defination of signal in psedocode is:
signal(s)
{
s++;
}
Modification to the integer value of smaphore in wait and signal operations must be executed
individually.
That is, when one process modifies the semaphore value no other process can simultaneously
modifiy that same semaphore value.
LOVELY PROFESSIONAL UNIVERSITY 103