educative.io

Won't semaphore cause race condition?

According to the picture illustrating semaphore, it can be seen that two threads are entering the critical section, won’t it cause race condition?

Hi @Nilesh_Jha
Semaphore allows multiple process threads to access the finite instance of the resource until available by using two atomic operations i.e. wait and signal. The value of the semaphore variable can be modified by any process that needs some resource, but only one process can change the value at a time. So because of all these things, race conditions do not occur