Why is stack size needed to spawn a task

Jan 22, 2007 3 Replies

For spawnig a task, taskSpawn() requires stack size as a paramter. Is the stack size needed to limit the usage of memory by the task? Cant the system allow the tasks to use how much ever memory it wants? Please let me know the answer. Senthil KAS



Why can't the system allow me to spend anything I want to?

"A man who is right every time is not likely to do very much." -- Francis Crick, co-discover of DNA "There is nothing more amazing than stupidity in action." -- Thomas Matthews

Not to limit, but the stack needs to be allocated.

Only if you have a Memory Management Unit in your CPU. With a MMU, stacks can grow dynamically until all memory is exhausted.

The system doesn't know ahead of time how much stack the process needs, so starting with an unknown stack size would require resizing the stack.

It would be difficult to design an OS that can cope with a stack that moves around, and you'd have to move it around to resize it. An MMU would help with this moving, but some difficulty would remain.

Moving a stack would also take time, so if your application is real time the notion of having a task sporadically stop to move the stack around whenever it needed to grow.

Embedded systems generally run with a limited amount of resources, so having the stack spaces growing dynamically would give most developers the willies. What happens if your OS runs out of stack space for The Most Important Task because some low-priority task was greedy? I'm certainly far more comfortable with the idea of having everything statically allocated, then verifying that I'll never blow the stack space.

Tim Wescott Wescott Design Services http://www.wescottdesign.com Posting from Google? See http://cfaj.freeshell.org/google/ "Applied Control Theory for Embedded Systems" came out in April. See details at http://www.wescottdesign.com/actfes/actfes.html

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required