cancel
Showing results for 
Search instead for 
Did you mean: 

New Lib reentrant using C++ and RTOS

MC.5
Associate

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"

1 ACCEPTED SOLUTION

Accepted Solutions
Pavel A.
Evangelist III

> 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.

View solution in original post

4 REPLIES 4
Pavel A.
Evangelist III

> 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.

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

Pavel A.
Evangelist III

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.