Bird
0
0

How can you ensure a task created with xTaskCreate() receives a parameter safely?

hard📝 Application Q9 of 15
FreeRTOS - Task Creation and Management
How can you ensure a task created with xTaskCreate() receives a parameter safely?
APass a local variable's address from the creating function
BPass a pointer to a variable that remains valid during the task lifetime
CPass NULL and set the parameter inside the task
DPass a copy of the parameter by value
Step-by-Step Solution
Solution:
  1. Step 1: Understand parameter passing in xTaskCreate()

    The parameter is passed as a void pointer to the task function.
  2. Step 2: Identify safe parameter passing

    Passing a pointer to a variable that remains valid ensures the task accesses correct data. Passing a local variable's address is unsafe as it may go out of scope.
  3. Final Answer:

    Pass a pointer to a variable that remains valid during the task lifetime -> Option B
  4. Quick Check:

    Parameter pointer must remain valid for task use [OK]
Quick Trick: Parameter pointer must outlive the task [OK]
Common Mistakes:
  • Passing address of local variables
  • Assuming NULL parameter is always safe
  • Trying to pass by value directly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FreeRTOS Quizzes