malloc/free thread & interrupt-safe

lucky-joe wrote on Monday, April 09, 2007:

Hi @all,

I am using the arm7-gcc port of FreeRTOS with the Aeolus-newlib syscall-stub with some modifications and it works fine. But now I have a question concerning the malloc/free-mechanism during interrupts. At the moment i also use the heap_3.c module which uses the standard-malloc/free because I do not have hard deterministic requirements. But I unsure if this malloc/free (sbrk_r) also works during interrupts and if it is thread safe.
Does anyone know more about my requirements or does someone have a solution for my question ?

regards
Joe

nobody wrote on Monday, April 09, 2007:

You cannot use pvPortMalloc or vPortFree from an interrupt because they use critical sections to ensure they are thread safe.  You could use standard malloc and free from an interrupt, provided you only use the thread safe versions from outside of the interrupt.

However, generally it would be considered bad practice to call such a potentially large and non deterministic function such as malloc from within an interrupt in any case.

Dave.

lucky-joe wrote on Monday, April 09, 2007:

Ok, I will check another way to implement my requirements. You have right with the statement of bad practise, may be i will check the possiblity using preallocated blocks

Joe