Bird
0
0

You want to create two tasks with different priorities using xTaskCreate(). Which code snippet correctly creates both tasks and stores their handles?

hard📝 Application Q15 of 15
FreeRTOS - Task Creation and Management
You want to create two tasks with different priorities using xTaskCreate(). Which code snippet correctly creates both tasks and stores their handles?
ATaskHandle_t handle1, handle2; xTaskCreate(Task1, "Task1", 1000, NULL, 5, handle1); xTaskCreate(Task2, "Task2", 1000, NULL, 3, handle2);
BTaskHandle_t handle1, handle2; xTaskCreate(Task1, "Task1", 1000, NULL, 3, &handle1); xTaskCreate(Task2, "Task2", 1000, NULL, 5, &handle2);
CTaskHandle_t handle1, handle2; xTaskCreate(Task1, Task1, 1000, NULL, 3, &handle1); xTaskCreate(Task2, Task2, 1000, NULL, 5, &handle2);
DTaskHandle_t handle1, handle2; xTaskCreate(Task1, "Task1", 1000, NULL, 3, &handle2); xTaskCreate(Task2, "Task2", 1000, NULL, 5, &handle1);
Step-by-Step Solution
Solution:
  1. Step 1: Verify task handle usage

    Each task handle must be passed by address using &. TaskHandle_t handle1, handle2; xTaskCreate(Task1, "Task1", 1000, NULL, 3, &handle1); xTaskCreate(Task2, "Task2", 1000, NULL, 5, &handle2); correctly does this for both handles.
  2. Step 2: Check task names and priorities

    Task names are strings in quotes. Priorities differ (3 and 5) as required. TaskHandle_t handle1, handle2; xTaskCreate(Task1, "Task1", 1000, NULL, 3, &handle1); xTaskCreate(Task2, "Task2", 1000, NULL, 5, &handle2); matches this correctly.
  3. Step 3: Confirm no parameter mix-ups

    TaskHandle_t handle1, handle2; xTaskCreate(Task1, "Task1", 1000, NULL, 5, handle1); xTaskCreate(Task2, "Task2", 1000, NULL, 3, handle2); misses & operator. TaskHandle_t handle1, handle2; xTaskCreate(Task1, Task1, 1000, NULL, 3, &handle1); xTaskCreate(Task2, Task2, 1000, NULL, 5, &handle2); uses function names instead of strings for task names. TaskHandle_t handle1, handle2; xTaskCreate(Task1, "Task1", 1000, NULL, 3, &handle2); xTaskCreate(Task2, "Task2", 1000, NULL, 5, &handle1); swaps handles incorrectly.
  4. Final Answer:

    TaskHandle_t handle1, handle2; xTaskCreate(Task1, "Task1", 1000, NULL, 3, &handle1); xTaskCreate(Task2, "Task2", 1000, NULL, 5, &handle2); -> Option B
  5. Quick Check:

    Correct handles and priorities = TaskHandle_t handle1, handle2; xTaskCreate(Task1, "Task1", 1000, NULL, 3, &handle1); xTaskCreate(Task2, "Task2", 1000, NULL, 5, &handle2); [OK]
Quick Trick: Pass &handle for each task, use quoted names, set priorities properly [OK]
Common Mistakes:
  • Passing handles without &
  • Using function names instead of string names
  • Mixing up handles between tasks

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FreeRTOS Quizzes