What is a semaphore?

Answer Posted / sagarika mishra

In computer science, a semaphore is a protected variable or
abstract data type which constitutes the classic method for
restricting access to shared resources such as shared
memory in a multiprogramming environment. A counting
semaphore is a counter for a set of available resources,
rather than a locked/unlocked flag of a single resource. It
was invented by Edsger Dijkstra. Semaphores are the classic
solution to preventing race conditions in the dining
philosophers problem, although they do not prevent resource
deadlocks.
Semaphores can only be accessed using the following
operations. Those marked atomic should not be interrupted
(that is, if the system decides that the "turn is up" for
the program doing this, it shouldn't stop it in the middle
of those instructions) for the reasons explained below.
P(Semaphore s) // Acquire Resource
{
wait until s > 0, then s := s-1;
/* must be atomic because of race conditions */
}

V(Semaphore s) // Release Resource
{
s := s+1; /* must be atomic */
}

Init(Semaphore s, Integer v)
{
s := v;
}

Is This Answer Correct ?    29 Yes 12 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is multitask win95

777


Is go garbage collected?

759


Can a laptop have both ssd and hdd?

836


i want information about real time operating systems because i have an interview tomoorow in valeo company.

3222


Which one is the best operating system?

721


What is Cycle Stealing in OS?

806


What is the best free operating system?

753


What is the difference between the OS which you use and other OSs?

763


What is a Safe State and what is its use in deadlock avoidance?

764


wha is very first process created by kernel

785


How many bytes we can send to apple push notification server in iOS operating system?

821


What is the name of first operating system?

672


What do you know about the latest android version Lollipop?

720


What Command To Restore Backup Of Non - Rootvg?

844


Is 6 cores enough for streaming?

764