RTOS Basics : Mutex
Amruta (talk) 13:17, 14 April 2015 (IST)
Intro
Mutex is a special type of binary semaphore used for controlling access to the shared resource. It is used to avoid extended priority inversion using priority inheritance technique. Check this to know more about priority inversion.
Priority inheritance can be implemented in two ways : changing the priority of the task trying to access the mutex
- to the priority equal to the priority of the task acquiring the mutex or
- to the higher priority than the priority of the task acquiring the mutex
so that the task trying to access the mutex will immediately get the mutex when other task releases the mutex.
The first way as adopted in FreeRTOS.
API Details
Create Mutex
Defination | vSemaphoreCreateMutex( xSemaphoreHandle xSemaphore ) |
Input Arguments | xSemaphoreHandle : It is a handle to the created mutex.
It can be used futher to use other semaphore APIs. |
Return Value | none |
Description | It creates the mutex.
It writes non NULL value to the argument xSemaphoreHandle if mutex is created. |
Usage | xSemaphoreHandle Sem_A = NULL;
vSemaphoreCreateMutex(Sem_A); |
All other APIs required to use the mutex are same as semaphore. You can find them here.