operating-systems concurrency

Definition

Counting Semaphore

A counting semaphore is a semaphore that can take any non-negative integer value. It controls access to a pool of multiple resource instances.

The initial value represents the number of available resources.

Operations

OperationEffect
wait(S)Decrements ; if , the process blocks
signal(S)Increments ; if processes are blocked, one is unblocked

Applications

Resource Tracking

Each wait() allocates a resource; each signal() releases one. The count tracks availability.

Synchronisation

Used in the Producer-Consumer Problem to track full and empty buffer slots.

Negative Values

In implementations where the semaphore value may become negative, represents the number of blocked processes waiting in the queue.