Mutex 和 Semaphore=1 的区别?

Difference between Mutex and Semaphore=1?

下面两个变量有区别吗:

Mutex m;
Semaphore s = 1;

我认为它们是相同的,但在视频中我正在观看有关 reader/writer 问题的公式,它说使用 5 信号量,每个信号量都从 1。我发现这很有趣,因为我认为如果你有一个值为 1 的信号量,那么你只需使用一个互斥锁。

将 Mutex 视为信号量定义的子集。

Stack Overflow 上有一个很好的答案:Difference between binary semaphore and mutex .

Mutex can be released only by thread that had acquired it, while you can signal semaphore from any other thread (or process), so semaphores are more suitable for some synchronization problems like producer-consumer.