Mutexes
The term mutex is shorthand for mutual exclusion. In the context of shared-resources and tasks, mutual exclusion means that if a task is using a shared-resource, then that task is the only task that is permitted to use the resource – all others will need to wait. If this sounds a lot like a binary semaphore, that’s because it is.
This section explains what mutexes are, and how to work with them. Also, an example-program is presented.
Understanding mutexes
In FreeRTOS, mutexes are binary semaphores with one important additional feature. That feature is priority inheritance – mutexes have the ability to temporarily change the priority of a task to avoid causing major delays in the system. This plays out when the scheduler finds that a high-priority task is attempting to acquire a mutex already held by a lower-priority task. In this specific case, the scheduler will temporarily increase the priority of the lower task until it releases the mutex...