semaphore and mutex

The best paper that describes the difference between semaphore and mutex is in the links below, I have not found any article that is better on articulating.

therefore I suggest you read the link below to understand the difference between semaphore and mutex.

http://blog.feabhas.com/2009/09/mutex-vs-semaphores-%E2%80%93-part-1-semaphores/

http://blog.feabhas.com/2009/09/mutex-vs-semaphores-%E2%80%93-part-2-the-mutex/

http://blog.feabhas.com/2009/10/mutex-vs-semaphores-%E2%80%93-part-3-final-part-mutual-exclusion-problems/

following is a short summary of the above 3 links, I don't take any credit for it, :-)

Semaphore is ownerless, hence it suffer the following problems when used as coordination primitive:

1. mistaken release. Anybody can release a semaphore.

2. self-induced deadlock, or recursive deadlock, or itself takes the semaphore multiple times.

3. Owner death introduced deadlock. Nobody can revive the semaphore.

4. Priority inversion. ( can be fixed via priority inheritance and priority ceiling protocol )

5. Circular deadlock. Two task depends on each other (this issue cannot be fixed by mutex, all other 4 issue can be fixed by mutex)

However semaphore can be used for the following task that mutex cannot do:

1. synchronization primitive.

2. asynchronous signal and interrupt safe. meaning they can be used inside a signal handler and interrupt handler without side effects.