Some semaphore implementations provide a function getValue() that returns the current value of a semaphore. This function may, for instance, be invoked prior to calling wait() so that a process will only call wait() if the value of the semaphore is > 0, thereby preventing blocking while waiting for the semaphore. For example:

if (getValue(&sem)>0
wait(&sem);

What is the problem in this approach?

Respuesta :

Answer and Explanation:

The values of the semaphore can always be 0 for a particular process A, because whenever process A checks the

value by using getValue(&sem), some process B can be using the semaphore, after process B releases and puts

the value to 1, some other process C can get that semaphore by seeing the value > 0 and decrements its value

to 0 again. Now If the process A comes again It will see the value to be 0 again and this can go on ....

process A will never get the semaphore.

ACCESS MORE