wisemonkeys logo
FeedNotificationProfileManage Forms
FeedNotificationSearchSign in
wisemonkeys logo

Blogs

semaphores in os

profile
Dia Jha
Aug 15, 2024
0 Likes
0 Discussions
74 Reads

In Operating Systems: Semaphores


Semaphors are one of the most important concepts in OS,it is mainly used to synchronise and control access on any concurrent process or threads. They protect against race conditions and make sure that multi-process environment uses resources effectively, and safely.


 1. Definition and Types


 A semaphore is a synchronization tool,that uses an integer value for controlling access to any shared resource. The semaphore can work after adjustment of its value by two atomic operations


– Wait (P of Proberen): Decreases the semaphore value. Is the value goes below 0 then until it becomes positive again, that process will be on hold.


- Signal (V or Verhogen): This processes signals increase the value of semaphore. if value is less then calls up blocked process.


There are two kind of semaphores:-


Binary Semaphore (Mutex): This can only take two values 0 and 1. It is used to do compliant access on one resource.


- Counting Semaphore: can yield any integer value and they are used to control access of a finite number of instances for a resource.


 2. Usage


Some of the scenarios using semaphores are as follows:


Mutex: mutual exclusion, which allows only a single process or thread to enter the critical section of the code.


- Resource Sharing: It manages access to a pool of identical resources—such as database connections.


Process Synchronization- It controls running of the processes in a certain order, it allows only specific operations to conduct at some time.


3. Implementation and Challenges


This signal is generally created in the kernel of an operating system and makes use of specific functions. Semaphores come with a few challenges out of the box:


On the other hand, Deadlocks can occur if processes are waiting indefinitely for a semaphore.


-Priority Inversion: Prevent a high-priority process from moving forward by a low-priorit.


– Starvation: Some processes may never get access to a semaphore if continuous acquisition of it is being done by other processes.


 4. The Pro 's and Con's 


- Advantages:


Simple but efficient synchronization mechanism.


Allows control over the execution of processes and access to resources.


- Disadvantages:


 Disadvantages- Difficult to implement correctly (deadlocks, priority inversion).


Semaphores are difficult to be debugged


Summary


Semaphores are used to synchronize or coordinate execution of process among themselves and helps lot in maintaining access / modification order of shared resources. Appropriate use of semaphores Improves the performance and reliability in multi-process environment.


Comments ()


Sign in

Read Next

Topic: Sessions in Operating system

Blog banner

The Dark Web: A Breeding Ground for Cybercriminals – How to Guard Against Threats

Blog banner

Online Games

Blog banner

A book review

Blog banner

Inventory management software system

Blog banner

Monday. com App

Blog banner

Email Privacy

Blog banner

Lemon and Chilli Pickle (Limbu Mirchi Achar)

Blog banner

MYNTRA

Blog banner

Blockchain uses and use cases

Blog banner

Deadlock and Starvation in an Operating System

Blog banner

Scala - a programming tool

Blog banner

Memory management

Blog banner

BEAUTY IS IN THE EYE OF THE BEHOLDER

Blog banner

Proof-of-Stake (PoS)

Blog banner

Types of Malware in Cyber Security

Blog banner

Threads

Blog banner

GraphQL

Blog banner

GraphX:- A graph processing tool

Blog banner

memory cache

Blog banner

Memory management

Blog banner

Love is in air.....

Blog banner

Memory Management

Blog banner

5 People who claimed to have Time Traveled

Blog banner

Volatile Memory & Non-Volatile Memory Explained

Blog banner

Evolution of operating systems

Blog banner

Threads

Blog banner

Modern Operating Systems.

Blog banner

Safeguarding Your Data: The Importance of Wireless Encryption

Blog banner

An Overview of Virtual Machines

Blog banner

India Digital Personal Data Protection Act, 2023

Blog banner

Zero Trust Security Model: Revolutionizing Cybersecurity in the Digital Age

Blog banner

How to write a cover letter

Blog banner

10 Problems you face if you are an Otaku

Blog banner

Brain wash of social media

Blog banner

SMARTSHEET

Blog banner

Demystifying Cryptography: A Beginner's Guide

Blog banner

Mesh Topology

Blog banner

What if COVID does not exist!

Blog banner

Benefits and drawback of web security.

Blog banner

It's all about our Brain.- The Brain Metaphor

Blog banner

10 Interesting Facts about Death Note

Blog banner