[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] using malloc() in a SIGNAL function
From: |
David Brown |
Subject: |
Re: [avr-gcc-list] using malloc() in a SIGNAL function |
Date: |
Fri, 15 Apr 2005 13:41:41 +0200 |
> Hey.
> I am just doing some code reviewing.
> I found that the code uses the malloc() function inside a SIGNAL
> function, as well as in the maincode.
> I did not find anything about if that is safe, in the documentation. But
> looking in the lst-file I can see no cli instructions.
> But of cource, it could be protected againts reentry in other ways. But
> is it?
>
I haven't looked at the avrlibc implementation, but in general malloc is not
re-entrant and must therefore be explicitly protected (such as by disabling
interrupts in the main program before calling it - assuming your program is
happy with disabling interrupts for inderminant times). Of course, any use
of malloc in a small embedded system must be treated with extreme
suspicion - dynamic memory is on the list of "standard" C functionality that
should be avoided unless you are absolutely sure you need it and understand
all the consequences, along with things like printf and floating point
maths.