Download the BYJU'S Exam Prep App for free GATE/ESE preparation videos & tests - Download the BYJU'S Exam Prep App for free GATE/ESE preparation videos & tests -

Binary Semaphores in Operating System

Binary semaphores are synchronization mechanisms that have integer values that range from 0 (zero) to 1 (one). As a result, this type of semaphore gives a single point of access to a key portion. It signifies that only one individual will have simultaneous access to the critical part.

In this article, we will look more into the Binary Semaphores in Operating Systems according to the GATE Syllabus for (Computer Science Engineering) CSE. Let us read ahead to find out more about it.

Table of Contents

What are Binary Semaphores in Operating Systems?

The value of a semaphore variable in binary semaphores is either 0 or 1. The value of the semaphore variable is initially set to 1, but if a process requests a resource, the wait() method is invoked, and the value of this semaphore is changed from 1 to 0. When the process has finished using the resource, the signal() method is invoked, and the value of this semaphore variable is raised to 1. If the value of this semaphore variable is 0 at a given point in time, and another process wants to access the same resource, it must wait for the prior process to release the resource. Process synchronization can be performed in this manner.

Illustration of Binary Semaphores in OS

A flowchart depicting a typical procedure of an entity accessing a vital region controlled by the binary semaphore is shown below:

binary-semaphores-in-operating-system

Apart from synchronizing access to crucial parts, binary semaphores also allow mutual exclusion. As a result, race circumstances in vital areas can be avoided. However, it is important to note that, while binary semaphores provide mutual exclusion, they are not the same as mutexes. By definition, semaphores are signalling systems, whereas mutexes are locking mechanisms.

Mutexes allow mutual exclusion for accessing crucial code regions in this fashion. Binary semaphores, on the other hand, are concerned with synchronizing access to important parts. Mutexes’ principal objective is, thus, mutual exclusion. For binary semaphores, however, it is a result of the synchronization’s architecture.

In practice, a mutex only locks a vital area if an entity is present. Semaphores, on the other hand, can render a vital region inaccessible even if no entities are present. It can happen when, for example, an external precondition must be met before entities can access a key area.

Where are Binary Semaphores Used?

The mutual exclusion was not used in counting semaphore because we had a group of processes that needed to run in the crucial region at the same time. Binary Semaphore, on the other hand, rigorously enforces mutual exclusion. Instead of having many slots in the crucial part, we can only have one process in the critical portion here. There are just two possible values for the semaphore: 0 or 1.

Features of Binary Semaphore

  • A Binary Semaphore is one with an integer value between 0 and 1.
  • It’s nothing more than a lock with two possible values: 0 and 1. 0 denotes being busy, while 1 denotes being unoccupied.
  • The rationale behind a binary semaphore is that it only enables one process to enter the crucial area at a time, thus allowing it to access the resource that is shared.
  • The value 0 indicates that a process or thread is in the critical section, i.e. it is accessing a shared resource, and that the other processes or threads should wait for it to finish. The critical region, on the other hand, is free because no process is accessing the resource that is shared.
  • It ensures reciprocal exclusion by ensuring that no two processes are in the crucial section at the same time.
  • It cannot ensure bounded waiting because it is only a variable that retains an integer value. It’s possible that a process will never get a chance to enter the critical section, causing it to starve. We don’t want it to happen.

Video on Binary Semaphore

Keep learning and stay tuned to get the latest updates on GATE Exam along with GATE Eligibility Criteria, GATE 2023, GATE Admit Card, GATE Syllabus, GATE Previous Year Question Paper, and more.

Also Explore,

Comments

Leave a Comment

Your Mobile number and Email id will not be published.

*

*