First I want to make sure I'm understanding the behavior of what is happening when trying (and failing) to take a semaphore or mutex...
When this code runs (assuming xSemaphoreTake is going to fail to take the mutex), my understanding is that some_task would enter a blocked state for 1000 ticks then will be put into a ready state and again try to take some_mutex. BUT if only 500 ticks go by and the mutex is given, some_task would automatically enter the ready state. So what's the point of trying to take the mutex every so often (every 1000 ticks in this case) if the task will enter the ready state when the mutex is given regardless?
SemaphoreHandle_t some_mutex = xSemaphoreCreateMutex();
void some_task(void* parameters)
{
xSemaphoreTake(some_mutex, (TickType_t) 1000);
do_task_stuff();
xSemaphoreGive(some_semaphore);
}
On a side note, does adding an if statement around xSemaphoreTake cause any difference in the behavior?
SemaphoreHandle_t some_mutex = xSemaphoreCreateMutex();
void some_task(void* parameters)
{
if (xSemaphoreTake(some_mutex, (TickType_t) 1000) == pdPASS)
{
do_task_stuff();
}
xSemaphoreGive(some_semaphore);
}