2022-10-20 04:01 AM
I am confused on the topic of new lib reentrant and RTOS.
I use C++ and do some std::make_unique calls so malloc it's probably getting called under the hood.
I have enabled the setting configUSE_NEWLIB_REENTRANT for RTOS and I am using heap_4 memory scheme.
I am using a single core microcontroller from the family STM32L4.
Is this enough to avoid problems ?
I got confused by the posts on this topic by "nadler" and "mcuoneclipse"
Solved! Go to Solution.
2022-10-20 09:51 AM
> I got confused by the posts on this topic by "nadler" and "mcuoneclipse"
Welcome to the club :)
> I am using heap_4 memory scheme.
All heap_N except of heap_3 are not aware of the C library heap (malloc/free/new...).
Either make all allocations from the C heap before starting the RTOS scheduler (and avoid calling malloc &free from tasks), or read on thread-safe implementation of malloc/free for newlib.
2022-10-20 09:51 AM
> I got confused by the posts on this topic by "nadler" and "mcuoneclipse"
Welcome to the club :)
> I am using heap_4 memory scheme.
All heap_N except of heap_3 are not aware of the C library heap (malloc/free/new...).
Either make all allocations from the C heap before starting the RTOS scheduler (and avoid calling malloc &free from tasks), or read on thread-safe implementation of malloc/free for newlib.
2022-10-24 02:19 AM
Hi Pavel,
thank you a lot for the reply.
The codebase that I am working on makes all the objects allocations before starting freeRTOS. So I think that I am safe.
Do you think that I can avoid using the setting configUSE_NEWLIB_REENTRANT if I don't do dynamic allocation and I don't use the regular snprintf ?
Thank you again.
Kind regards,
Mattia
2022-10-24 06:06 AM
Hi Mattia
Newlib has some other functions that use the per-thread area (I don't remember which exactly). Likely yes, if the program does not use any of these in several threads, it can get away without configUSE_NEWLIB_REENTRANT.
2022-11-26 07:55 PM