Is it safely to call pvPortMalloc() before scheduler running?

ttx330 wrote on Thursday, November 14, 2019:

Hi, Guys
Our project was based on CR5, and used heap4.
As in our project we may do dynamic allocation before the scheduler running (actually before the hw timer being initialized) So i check the dependency between pvPortMalloc API and kernels. pvPortMalloc will call vTaskSuspendAll()/xTaskResumeAll() to ensure thread safety(as I understand), but In FreeRTOS reference manual said, xTaskResumeAll() should not be called before vTaskStartScheduler() being called.
Indeed I saw a yield manipulation in xTaskResumeAll() if the FreeRTOSConfig set preemption to 1. So i confused that, In xTaskCreate API it seems pvPortMalloc being called to create a TCB structure and xTaskCreate could be called before the scheduler start.
So, chould pvPortMalloc being called before scheduler start? If yes, How to explain the xTaskResumeAll() in pvPortMalloc

Thanks in advance

Yun

rtel wrote on Thursday, November 14, 2019:

Assuming you are using one of the 5 example heap allocation schemes we
provide, then yet it is fine to call pvPortMalloc() before the scheduler
starts - in fact unless you have configSUPPORT_DYNAMIC_ALLOCATION set to
0, in which case the system will be completely statically allocated, it
is not possible to start the scheduler without calling pvPortMalloc() as
it is called each time a task is created - including the idle task which
is created by the scheduler itself. xTaskResumeAll() will not attempt
to perform a context switch as there will be no tasks actually running
to switch to.