3 ms·
I think the main source of confusion is that mutexes and semaphores have different semantics, and people tend to forget that. You cannot easily (in userspace) i
by stplsd 12y ago
I think the main source of confusion is that mutexes and semaphores have different semantics, and people tend to forget that. You cannot easily (in userspace) implement mutex with semaphore(s) or semaphore with mutexe(s), because they by design have different semantics, i.e. mutexes have owners and semaphores do not, mutex can be unlocked only by thread who locked it, ant semaphore does not have this feature/limitation - any process/thread who have rights to access semaphore can unlock previously locked (by any thread/process) semaphore, trying this with mutexes will give you undefined behaviour, etc.
- jeffbush 12y agoI think it's actually pretty easy to implement a mutex with a semaphore. The opposite not so much. If you want extra debug checking, you can wrap the semaphore with another construct that sets the owner field on lock and checks it on unlock.