operating-systems concurrency

Definition

Counting Semaphore

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

The initial value of a counting semaphore typically represents the number of available resources.

Usage

  • Resource Tracking: Each wait() operation decrements the count (allocating a resource), and each signal() operation increments it (releasing a resource).
  • Synchronisation: Used in the Producer-Consumer Problem to keep track of the number of full and empty slots in a buffer.

Inconsistent Implementations

In the implementation shown in your notes (where the value can become negative), the absolute value when represents the number of processes currently blocked in the queue.