Semaphore

Why Trust Techopedia

What Does Semaphore Mean?

A semaphore is a synchronization object that controls access by multiple processes to a common resource in a parallel programming environment. Semaphores are widely used to control access to files and shared memory. The three basic functionalities associated with semaphores are set, check and wait until it clears to set it again. |

Advertisements

Semaphores are used to address benchmark synchronization problems.

The concept of semaphore was put forth by the Dutch computer scientist Edsger Dijkstra.

Techopedia Explains Semaphore

Semaphores are non-negative integer values that support the operations semaphore->P () and semaphore->V (). P is an atomic operation that waits for a semaphore to be positive and then decrements it by one, while V is an atomic operation that increments a semaphore by one, which implies it wakes up a waiting P. Test and set associated with semaphore are routines implemented in hardware to coordinate lower-level critical sections.

Semaphores are normally implemented using file descriptors. Semaphore creations are not atomic. If two processes try to create, initialize and use a semaphore at the same time, a race condition is created. Semaphores are created and initialized to a positive value to show the availability of a resource to be used. Semaphores can be implemented through interrupts or by using test-set operations.

Every semaphore maintains sets of permits. It restricts the number of threads accessing the resources. Semaphores with only one permit and initialized to one serve as mutual exclusion locks. They are referred to as such because they have only two states: permit available or zero permit available. This encloses the property so that a lock can be released by a thread other than the owner, helping in deadlock recovery. Semaphores are used for mutual exclusions where the semaphore has an initial value of one, and P () and V () are called before and after the critical sections.

Advertisements

Related Terms

Margaret Rouse
Technology expert
Margaret Rouse
Technology expert

Margaret is an award-winning writer and educator known for her ability to explain complex technical topics to a non-technical business audience. Over the past twenty years, her IT definitions have been published by Que in an encyclopedia of technology terms and cited in articles in the New York Times, Time Magazine, USA Today, ZDNet, PC Magazine, and Discovery Magazine. She joined Techopedia in 2011. Margaret’s idea of ​​a fun day is to help IT and business professionals to learn to speak each other’s highly specialized languages.