What are Semaphores?

Semaphores :

  • Semaphores, in its most basic form, is a protected integer variable that can facilitate and restrict access to shared resources in a concurrent environment.
  • A semaphore S is an integer variable that, apart from initialization, is accessed only through two standard atomic operations: wait() and signal().
  • The wait() operation was originally termed as P and signal() was originally called as V.
  • The definition of wait():
  • The definition of signal() is as follows:
  • All modifications to the integer value of the semaphore in the wait() and signal() operations must be executed indivisibly. That is, when one process modifies the semaphore value, no other process can simultaneously modify that same semaphore value.
  • In addition, in the case of wait(S), the testing of the integer value of S (S ≤ 0), as well as its possible modification (S–), must be executed without interruption.

Counting Semaphore :

  • The value of a counting semaphore can range over an unrestricted domain.
  • Counting semaphores can be used to control access to a given resource consisting of a finite number of instances.

Binary Semaphore :

  • The value of a binary semaphore can range only between 0 and 1.
  • Thus, binary semaphores behave similarly to mutex locks, but are not same. Semaphores use signalling mechanism whereas Mutex uses locking mechanism
  •  In fact, on systems that do not provide mutex locks, binary semaphores can be used instead, for providing mutual exclusion.

Leave a Reply

Your email address will not be published. Required fields are marked *