Hi,
I have a question regarding the usage and behaviour of Mutex vs Semaphore in RTX v4.7, in which I have two threads that needs to access a critical section.
Obviously Mutex seems to be the more appropriate choice than Semaphore since only 1 token is enough to control access to the critical section...however I need to release the token in ISR and Mutex does not allow this while Semaphore does..
What makes the difference here?
Thanks.
Mutex's are owned by threads. The thread that acquires the Mutex must be the one that releases the Mutex (It is a failure to release a mutex that you do not own). An ISR is not a thread so it cannot acquire a Mutex, Own a Mutex or Release a Mutex. Semaphores are more of a token based thing with no concept of the Semaphore being "owned" - you just "get" a token. Any entity can grab a token and any entity can release a token even without "having/owning" a token in the first place.
Oh this makes much more sense now...
Thats why the Barr article articulates that Semaphore and Mutex are distinctly different.
Its really easy to confuse these two when only consulting books or references.
Many thanks!