Memory allocation thread and interrupt safety
Posted: Tue Dec 11, 2018 10:54 pm
Hi there!
Could anyone clarify for me please whether malloc/new are thread and interrupt safe? I can see that there is an implementation of _malloc_r in newlib directory which is considered to be thread safe. But what about common malloc? Regarding to the documentation it seems that malloc and _malloc_r wrap the same functions, however, I can not confirm that since I can not find malloc implementation anywhere. And what about new operator? Is it a simple wrapper about malloc as it used to be? Also I am not sure whether it is safe to call malloc/new inside an ISR.
Actually I do not like the idea of calling malloc inside interrupt handler, therefore I would like to write my own block memory allocator for allocating objects in ISR, however, I am not sure how to make it safe if interrupts are nested. Is portENTER_CRITICAL_ISR enough to prevent nesting?
Could anyone clarify for me please whether malloc/new are thread and interrupt safe? I can see that there is an implementation of _malloc_r in newlib directory which is considered to be thread safe. But what about common malloc? Regarding to the documentation it seems that malloc and _malloc_r wrap the same functions, however, I can not confirm that since I can not find malloc implementation anywhere. And what about new operator? Is it a simple wrapper about malloc as it used to be? Also I am not sure whether it is safe to call malloc/new inside an ISR.
Actually I do not like the idea of calling malloc inside interrupt handler, therefore I would like to write my own block memory allocator for allocating objects in ISR, however, I am not sure how to make it safe if interrupts are nested. Is portENTER_CRITICAL_ISR enough to prevent nesting?