[ECOS] yet another stack saving scheme
Mon Aug 2 11:39:00 GMT 2004
This scheme is much more reasonable than my last idea :-)
I have a couple of places in my code that get invoked intermittantly
where stack usage is high and maximum stack usage is hard to estimate
with great confidence.
When the threads go back to "idle/waiting" mode, stack usage is minimal
and it is relatively straightforward to determine the precise amount of
One way to deal with this is to dynamically allocate memory for a new
stack and switch to that stack for the duration of the operation that
takes a lot of stack.
With eCos the most reasonable way to do this would be to create a new
thread with a suitably large stack, run the operation in question on
that thread and free up the thread/stack afterwards.
Wrapping this up in a nice fn should be relatively easy:
// returns true if stack could be allocated and fn was run
bool moreStack(int bytes, void (*fn)());
// do stack intensive stuff here
// wait for more to do.
if (!moreStack(10000, foo))
// application needs to decide what
// should happen in this case.
// sleep + retry?
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
More information about the Ecos-discuss