wisemonkeys logo
FeedNotificationProfileManage Forms
FeedNotificationSearchSign in
wisemonkeys logo

Blogs

semaphores

profile
Khyati Sanghavi
Aug 14, 2024
0 Likes
0 Discussions
60 Reads

Khyati sanghavi ,53003230018

Semaphores

A semaphore is an integer variable used for signalling among processes. It has three atomic operations:

  1. Initialisation: The semaphore is initialised with a non-negative integer value, which represents the number of available slots or resources.
  2. Decrement (semWait): When a process wants to access a shared resource, it decrements the semaphore value. If the resulting value is non-negative, the process can proceed. If the value becomes negative, the process is blocked and added to a waiting queue.
  3. Increment (semSignal): When a process releases a shared resource, it increments the semaphore value. If there are processes waiting in the queue, one of them is awakened and allowed to proceed.

How Semaphores Work

The value of a semaphore determines how many processes can proceed without blocking. When a process decrements the semaphore and the value becomes negative, it means that there are no more available slots or resources. The process is then blocked, waiting for another process to release a resource and increment the semaphore.

When a process increments the semaphore, it signals that a resource has been released. If there are processes waiting in the queue, one of them is awakened and allowed to proceed. This process can then decrement the semaphore and access the shared resource.

Advantages of Semaphores

  • Supports coordination between multiple processes
  • Provides a flexible and robust way to manage shared resources.
  • It can be used to implement critical sections in a program.
  • It can be used to avoid race conditions.

Disadvantages of Semaphores

  • It Can lead to performance degradation due to overhead associated with wait and signal operations.
  • Can result in deadlock if used incorrectly.
  • It can cause performance issues in a program if not used properly.
  • It can be difficult to debug and maintain.
  • It can be vulnerable to certain types of attacks, such as denial of service attacks.

Comments ()


Sign in

Read Next

PROCESS STATE:

Blog banner

12 Principles of Animation

Blog banner

Harsh Rathod

Blog banner

Internet: The Vast Ocean Of Knowledge.

Blog banner

Music

Blog banner

MPL and how its effects?

Blog banner

Big Data

Blog banner

WHAT IS TWITTER AND HOW DOES IT WORK

Blog banner

Sagar Parikrama

Blog banner

Protein and Energy: Why Your Workday Diet Needs More of It

Blog banner

Time Series Analysis

Blog banner

Why Meal Maharaj Prioritises Seasonal Vegetables in Every Meal Box

Blog banner

Precision-Recall in Data Science

Blog banner

"The Benefits of Using GIS in Agriculture"

Blog banner

5 Stages of Digital Marketing

Blog banner

A Traveller’s Guide to Offbeat Places in Arcadia, Florida

Blog banner

Outlook mail

Blog banner

HOW CAN SOCIAL MEDIA MAKE YOU HAPPIER?

Blog banner

Direct Memory Access

Blog banner

Firewall in Computer Network

Blog banner

security controls

Blog banner

Travel Geek ‘The last $50k in Switzerland’

Blog banner

Deadlock

Blog banner

INTRODUCTION

Blog banner

Threads in OS

Blog banner

Danger assessment in GIS

Blog banner

Fault Tolerance

Blog banner

Fossil Hunting 101 at the Peace River, Arcadia, Florida, USA

Blog banner

Deadlock and Starvation in an Operating System

Blog banner

Pooja Silver

Blog banner

Uniprocessor Scheduling

Blog banner

MY MOST THRILLED TREK ..... BHAIRAVGAD

Blog banner

FASHION

Blog banner

Memory management

Blog banner

Soak knowledge and level up your intellectual potential!!!

Blog banner

Blog on Smartsheet.

Blog banner

Daycare Centres Help Children Transition into Structured Learning

Blog banner

MOBILE DEVICE FORENSIC

Blog banner

Data-Driven Prediction of Virtual Item Prices in Online Games

Blog banner

Layers Of Blockchain

Blog banner

Philadelphia Experiment : Was it real?

Blog banner

Annual Day Preparation for Toddlers: What Helps and What to Avoid

Blog banner