1.Mutex
Is a key to a toilet. One person can have the key - occupy the toilet - at the time. When finished, the person gives (frees) the key to the next person in the queue.
Officially: "Mutexes are typically used to serialise access to a section of re-entrant code that cannot be executed concurrently by more than one thread. A mutex object only allows one thread into a controlled section, forcing other threads which attempt to gain access to that section to wait until the first thread has exited from that section."
A mutex is really a semaphore with value 1.
(Ref: Symbian Developer Library)

2. Semaphore:
Is the number of free identical toilet keys. Example, say we have four toilets with identical locks and keys. The semaphore count - the count of keys - is set to 4 at beginning (all four toilets are free), then the count value is decremented as people are coming in. If all toilets are full, ie. there are no free keys left, the semaphore count is 0. Now, when eq. one person leaves the toilet, semaphore is increased to 1 (one free key), and given to the next person in the queue.
Officially: "A semaphore restricts the number of simultaneous users of a shared resource up to a maximum number. Threads can request access to the resource (decrementing the semaphore), and can signal that they have finished using the resource (incrementing the semaphore)."
(Ref: Symbian Developer Library)

3. My understanding:
MUTEX作为互斥量,用于关键区域的互斥操作。它是有归属的,就是一个MUTEX必须是由得到它的进程或者任务进行释放。
而二值信号量则不用。任何一个 任务都可以post一个信号量,而释放一个MUTEX必须由拥有它的进程来完成。
我的理解就是在使用的时候,MUTEX在一个任务里面应该成对的使用,而二值信号量则不必如此。
因此在中断处理函数里面应该使用二值信号量而不是MUTEX.

From Internet:
1、临界区只能用于对象在同一进程里线程间的互斥访问;互斥体可以用于对象进程间或线程间的互斥访问。
2、临界区是非内核对象,只在用户态进行锁操作,速度快;互斥体是内核对象,在核心态进行锁操作,速度慢。
3、临界区和互斥体在Windows平台都下可用;Linux下只有互斥体可用。

在有的系统中Binary semaphore与Mutex是没有差异的。在有的系统上,主要的差异是:
mutex一定要由获得锁的进程来释放。而semaphore可以由其它进程释放< Symbian要求这样 >(这时的semaphore实际就是个原子的变量,大家可以加或减),因此semaphore可以用于进程间同步。Semaphore的同步功能是所有系统都支持的,而Mutex能否由其他进程释放则未定,因此建议mutex只用于保护critical section。而semaphore则用于保护某变量,或者同步。

4.Spin Lock
Spin lock是一个内核态概念。spin lock与semaphore的主要区别是spin lock是busy waiting,而semaphore是sleep。对于可以sleep的进程来说,busy waiting当然没有意义。对于单CPU的系统,busy waiting当然更没意义(没有CPU可以释放锁)。
因此,只有多CPU的内核态非进程空间,才会用到spin lock。Linux kernel的spin lock在非SMP的情况下,只是关irq,没有别的操作,用于确保该段程序的运行不会被打断。其实也就是类似mutex的作用,串行化对 critical section的访问。但是mutex不能保护中断的打断,也不能在中断处理程序中被调用。而spin lock也一般没有必要用于可以sleep的进程空间。

5. 自旋锁和信号量对比
(Internet)在很多地方自旋锁和信号量可以选择任何一个使用,但也有一些地方只能选择某一种。下面对比一些两者的用法。

        表1-1自旋锁和信号量对比
 应用场合                                                                 信号量or自旋锁
 低开销加锁(临界区执行时间较快)                 优先选择自旋锁
 低开销加锁(临界区执行时间较长)                 优先选择信号量
 临界区可能包含引起睡眠的代码                         不能选自旋锁,可以选择信号量
 临界区位于非进程上下文时,此时不能睡眠     优先选择自旋锁,即使选择信号量也
                                                                                  只能用down_trylock非阻塞的方式