[ECOS] yet another stack saving scheme

Øyvind Harboe oyvind.harboe@zylin.com
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
stack usage.

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)());

void foo()
	// do stack intensive stuff here

void loop()
	for (;;)
		// wait for more to do.

		// processing
		if (!moreStack(10000, foo))
			// application needs to decide what 
			// should happen in this case.
			// sleep + retry?

Øyvind Harboe

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 mailing list