educative.io

Educative

Binary semaphore acquisition and release by another thread

In the case of the binary semaphore, it’s not explained what happens if another thread tries to acquire or release a semaphore whose singular permit is already acquired by different thread.


Type your question above this line.

Course: https://www.educative.io/collection/5307417243942912/5668546535227392
Lesson: https://www.educative.io/collection/page/5307417243942912/5668546535227392/4810492780478464

Hi @Christopher_Chan
So binary semaphore has only two states of 0 & 1. 0 means blocked, and 1 means its permit is available. When one thread acquires the permit, the state of the semaphore automatically changes to 0. If another thread tries to acquire the permit during this phase, it will get blocked or added to the waitlist. After the first thread releases the permit, thread two will line up in the ready queue and acquire the permit.