When will the task start after xTaskCreate()?

If task “A” is started and its task enter function is invoked, an xTaskCreate() is used to create a task “B” with a higher priority than “A.” When does the task (B) start after the creation?

  1. After invoking the xTaskCreate() function, the new task (B) will start running immediately if it has a higher priority than the current task. The new task will run until it yields or is preempted by a task with an even higher priority. At that point, the current task will resume running (A). Then, xTaskCreate() will return.

  2. Task “B” will be created. xTaskCreate() will return the result, and “A” will be suspended.

It’s 1. (can be checked in the source tasks.c or by stepping through your code with a debugger)
Regarding 2. there would be no point where after returning from xTaskCreate function in task A the scheduler could be magically invoked.

1 Like

It is 1 as @hs2 mentioned. These lines ensure that - FreeRTOS-Kernel/tasks.c at main · FreeRTOS/FreeRTOS-Kernel · GitHub.

1 Like