Parallel programming - Semaphore (Counter Variable)

1 - About

A semaphore is a variable that control the access (physical or logical) by multiple thread to a common resource.

They are used for synchronization between two or more processes.

3 - Example

3.1 - Stoplight

If the stoplight is green, a train can enter the train station. If it is yellow or red (or any other color), the train station cannot be accessed.

3.2 - Connection Pool

With an application that supports max 10 connection, a semaphore with the value 10 will be created.

  • Whenever the application creates a connection, the semaphore will be decremented by 1.
  • Whenever the application disconnect a connection, the semaphore will be incremented by 1.
  • When the semaphore is above 10, the application will wait or return a message.

4 - Documentation / Reference

Data Science
Data Analysis
Data Science
Linear Algebra Mathematics

Powered by ComboStrap