ミューテックス
mutex is a locking mechanism that sometimes uses the same basic implementation as the binary semaphore. However, they differ in how they are used. While a binary semaphore may be colloquially referred to as a mutex, a true mutex has a more specific use-case and definition, in that only the task that locked the mutex is supposed to unlock it. This constraint aims to handle some potential problems of using semaphores:
ところが、使用方法で異なる
バイナリセマフォは口語的にはミューテックスとして表現されるが、本当のミューテックスには具体的なユースケースと定義がある
ミューテックスをロックしたタスクのみが、ミューテックス自体をサイドロック解除することになっている点
この制約により、セマフォを用いることによる潜在的問題に対処できるようになる:
Priority inversion: If the mutex knows who locked it and is supposed to unlock it, it is possible to promote the priority of that task whenever a higher-priority task starts waiting on the mutex.
Premature task termination: Mutexes may also provide deletion safety, where the task holding the mutex cannot be accidentally deleted.
Termination deadlock: If a mutex-holding task terminates for any reason, the OS can release the mutex and signal waiting tasks of this condition.
Recursion deadlock: a task is allowed to lock a reentrant mutex multiple times as it unlocks it an equal number of times.
Accidental release: An error is raised on the release of the mutex if the releasing task is not its owner.