Other Thread Components

Let's discuss some more thread components.

The threading module includes support for other items too, i.e. Semaphore and Barrier.

Semaphore

You can create a Semaphore which is one of the oldest synchronization primitives in computer science. Basically, a Semaphore manages an internal counter which will be decremented whenever you call acquire on it and incremented when you call release. The counter is designed in such a way that it cannot go below zero. So if you happen to call acquire when it’s zero, then it will block.

Simple example of Semaphore

Get hands-on with 1400+ tech skills courses.