Bird
0
0

What is wrong with this FreeRTOS design pattern code snippet?

medium📝 Debug Q14 of 15
FreeRTOS - Design Patterns for RTOS
What is wrong with this FreeRTOS design pattern code snippet?
void TaskA(void *pvParameters) {
  xSemaphoreTake(mutex, 0);
  // critical section code
  xSemaphoreGive(mutex);
  vTaskDelete(NULL);
}
AUsing zero block time may cause task to skip critical section without waiting.
BMutex is given before taking it.
CvTaskDelete should be called before giving mutex.
DCritical section code is missing.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze semaphore take with zero block time

    Using zero block time means the task tries to take the mutex but does not wait if it's unavailable, possibly skipping the critical section.
  2. Step 2: Understand impact on reliability

    This can cause unreliable behavior because the task may not execute the critical section safely every time.
  3. Final Answer:

    Using zero block time may cause task to skip critical section without waiting. -> Option A
  4. Quick Check:

    Zero wait risks skipping mutex [OK]
Quick Trick: Zero wait means no blocking; task may skip critical section [OK]
Common Mistakes:
  • Thinking mutex is given before taken
  • Believing vTaskDelete order matters here
  • Assuming critical section must be shown

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FreeRTOS Quizzes