Complete the code to create a mutex in FreeRTOS.
SemaphoreHandle_t xMutex = [1]();The function xSemaphoreCreateMutex() creates a mutex in FreeRTOS.
Complete the code to take (lock) the mutex before accessing a shared resource.
if(xSemaphoreTake(xMutex, [1]) == pdTRUE) { // Access shared resource }
Using portMAX_DELAY makes the task wait indefinitely until the mutex is available.
Fix the error in releasing the mutex after using the shared resource.
xSemaphore[1](xMutex);To release the mutex, use xSemaphoreGive().
Fill both blanks to correctly protect a shared variable with a mutex.
if(xSemaphore[1](xMutex, portMAX_DELAY) == pdTRUE) { sharedVar [2] 10; xSemaphoreGive(xMutex); }
Use xSemaphoreTake to lock the mutex and += to update the shared variable safely.
Fill all three blanks to create, take, and give a mutex protecting a shared counter.
SemaphoreHandle_t [1] = [2](); if(xSemaphoreTake([1], portMAX_DELAY) == pdTRUE) { counter++; xSemaphoreGive([1]); }
xSemaphoreCreateBinary() instead of xSemaphoreCreateMutex().Create the mutex with xSemaphoreCreateMutex(), store it in xMutex, then take and give it to protect the counter.
