Bird
0
0

You want to create two tasks and suspend the first one after creation using task handles. Which code snippet correctly achieves this?

hard📝 Application Q15 of 15
FreeRTOS - Task Creation and Management

You want to create two tasks and suspend the first one after creation using task handles. Which code snippet correctly achieves this?

void vTask1(void *pvParameters) { for(;;) {} }
void vTask2(void *pvParameters) { for(;;) {} }

int main() {
    TaskHandle_t xHandle1 = NULL, xHandle2 = NULL;
    // Create tasks here
    // Suspend first task here
    return 0;
}
AxTaskCreate(vTask1, "Task1", 1000, NULL, 1, &xHandle1); xTaskCreate(vTask2, "Task2", 1000, NULL, 1, &xHandle2); vTaskSuspend(NULL);
BxTaskCreate(vTask1, "Task1", 1000, NULL, 1, xHandle1); xTaskCreate(vTask2, "Task2", 1000, NULL, 1, xHandle2); vTaskSuspend(xHandle1);
CxTaskCreate(vTask1, "Task1", 1000, NULL, 1, &xHandle1); xTaskCreate(vTask2, "Task2", 1000, NULL, 1, &xHandle2); vTaskSuspend(&xHandle1);
DxTaskCreate(vTask1, "Task1", 1000, NULL, 1, &xHandle1); xTaskCreate(vTask2, "Task2", 1000, NULL, 1, &xHandle2); vTaskSuspend(xHandle1);
Step-by-Step Solution
Solution:
  1. Step 1: Correctly create tasks with handles

    Use &xHandle1 and &xHandle2 to store task handles during creation.
  2. Step 2: Suspend the first task using its handle

    Call vTaskSuspend(xHandle1); to suspend the first task by passing the handle itself, not its address or NULL.
  3. Final Answer:

    Correct creation with &xHandle and suspend with xHandle1 -> Option D
  4. Quick Check:

    Create with &handle, suspend with handle [OK]
Quick Trick: Create tasks with &handle, suspend using handle [OK]
Common Mistakes:
  • Passing handle instead of &handle to xTaskCreate
  • Passing &handle to vTaskSuspend instead of handle
  • Suspending with NULL handle

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FreeRTOS Quizzes