Qualcomm Interview Question
one more difference between mutex and semaphore is:
in mutex, only the process which locked the resource can unlock it.
while in semaphore, one process can put lock(decrements value) and other can unlock
e.g.: producer consumer problem
The semaphore type mentioned by JD is known as counting semaphore, where semaphore variable can have value greater than one.
semaphore variable which can have only 0 or 1 is known as binary semaphore.
Mutex is a binary semaphore . Mutex allows only one thread of execution in controlled section at one time forcing all other thread to wait for it to exit .
- JD January 25, 2010Semaphore restricts the number of simultaneous users of a shared resource . Initially it is equal to maximum number of resource available . Threads can request access to the resource (decrementing the semaphore), and can signal that they have finished using the resource (incrementing it )