Bird
0
0

Identify the issue in the following FreeRTOS task creation code snippet:

medium📝 Debug Q7 of 15
FreeRTOS - Task Creation and Management

Identify the issue in the following FreeRTOS task creation code snippet:

TaskHandle_t xTaskHandle = NULL;
void vTask(void *pvParameters) {
  for(;;) {
    vTaskDelay(1000 / portTICK_PERIOD_MS);
  }
}
int main() {
  BaseType_t res = xTaskCreate(vTask, "Task", 1000, NULL, 1, &xTaskHandle);
  if(res == pdPASS) {
    vTaskResume(xTaskHandle);
  }
  return 0;
}
ACalling vTaskResume immediately after task creation without suspending it first
BPassing &xTaskHandle instead of xTaskHandle to xTaskCreate
CUsing vTaskDelay inside the task function
DNot checking the return value of xTaskCreate
Step-by-Step Solution
Solution:
  1. Step 1: Analyze task creation and resume

    The task is created and immediately resumed without being suspended first.
  2. Step 2: Understand vTaskResume usage

    vTaskResume should only be called on a suspended task; newly created tasks start in the Ready state.
  3. Final Answer:

    Calling vTaskResume immediately after task creation without suspending it first -> Option A
  4. Quick Check:

    Resuming a non-suspended task is invalid [OK]
Quick Trick: Only resume tasks that are suspended [OK]
Common Mistakes:
  • Calling vTaskResume on a task that is not suspended
  • Ignoring task state before resuming

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FreeRTOS Quizzes