|
Home > Archive > Unix Programming > September 2007 > stack layout in multithreadded programs
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
stack layout in multithreadded programs
|
|
| Bahadir 2007-09-08, 1:31 pm |
| Hi,
A single threaded program could have layed out its stack at the top of
its memory area growing downwards. For example the typical program
layout is: (low mem) text/data/bss <----> stack. (high mem). Do you
have a description of how multithreaded programs would lay out their
stacks?
For instance imagine a program that forks threads into a shared
address space. How are the stacks layed out? What's the best solution?
Thanks,
Bahadir
| |
| Frank Cusack 2007-09-08, 7:24 pm |
| On Sat, 08 Sep 2007 15:52:20 -0000 Bahadir <Bilgehan.Balban@gmail.com> wrote:
> Hi,
>
> A single threaded program could have layed out its stack at the top of
> its memory area growing downwards. For example the typical program
> layout is: (low mem) text/data/bss <----> stack. (high mem). Do you
> have a description of how multithreaded programs would lay out their
> stacks?
text/data/bss <----> ... <---> stack <----> stack <----> stack
> For instance imagine a program that forks threads into a shared
> address space.
huh?
> How are the stacks layed out? What's the best solution?
Each new thread gets a stack mapped in bascially at some offset from
the top of the previous stack, determined by the stack size of the
previous thread. But you wouldn't simply keep going down in memory,
you'd want to fill in the holes where threads no longer exist.
I guess it would be a good idea to maintain a guard page in between
stacks. That is, when the stack hits a guard page don't automatically
map the next page in, check if there is only that one page left before
the next stack. That way you won't have stacks overrunning each
other.
-frank
| |
| Bahadir 2007-09-11, 1:18 pm |
| On 9 Sep, 00:07, Frank Cusack <fcus...@fcusack.com> wrote:
> On Sat, 08 Sep 2007 15:52:20 -0000 Bahadir <Bilgehan.Bal...@gmail.com> wrote:
>
>
>
> text/data/bss <----> ... <---> stack <----> stack <----> stack
>
>
> huh?
>
>
> Each new thread gets a stack mapped in bascially at some offset from
> the top of the previous stack, determined by the stack size of the
> previous thread. But you wouldn't simply keep going down in memory,
> you'd want to fill in the holes where threads no longer exist.
>
> I guess it would be a good idea to maintain a guard page in between
> stacks. That is, when the stack hits a guard page don't automatically
> map the next page in, check if there is only that one page left before
> the next stack. That way you won't have stacks overrunning each
> other.
>
> -frank
Hi,
Thanks this reply makes sense. It's how I anticipated it.
Bahadir
|
|
|
|
|