public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] yet another stack saving scheme
@ 2004-08-02 11:39 Øyvind Harboe
  0 siblings, 0 replies; only message in thread
From: Øyvind Harboe @ 2004-08-02 11:39 UTC (permalink / raw)
  To: ecos-discuss

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

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


-- 
Øyvind Harboe
http://www.zylin.com



--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-08-02 11:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-02 11:39 [ECOS] yet another stack saving scheme Øyvind Harboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).