4.1. Semaphores

Processes often need to coordinate access to a set of shared resources. A semaphore is a synchronization construct that was first used to solve concurrency problems in operating systems back in the 1960s. Today, they are commonly found in multithreaded programming languages, but are more difficult to achieve in distributed systems.

The conventional definition of a semaphore is an integer counter that represents the count of available resources at any given time. A semaphore is controlled by two operations:

  • down: checks to see if the counter is greater than zero, and if so, decrements its value by one. If the counter is zero, then the calling process blocks until the value is greater than zero. This operation is atomic: by calling ...

Get JavaSpaces™ Principles, Patterns, and Practice now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.