Hi,
below are possible reasons why creating a Task inside another task can cause Issues
- Stack Overflow: Each task in FreeRTOS has its own stack. If you create a task inside another task and the parent task has a small stack size, the creation process (which involves memory allocation and setup) might overflow the parent task’s stack.
- Scheduler State: If the scheduler is already running (vTaskStartScheduler() has been called), creating tasks dynamically is allowed. But if the task creation logic is flawed (e.g., creating tasks repeatedly without checking if they already exist), it can lead to memory exhaustion or undefined behavior.
- Priority and Timing: If the newly created task has a higher priority and immediately calls vTaskDelay(), it might cause a context switch that leads to unexpected behavior if the system isn't ready for it.
BR, Petr