stack layout in multithreadded programs
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > stack layout in multithreadded programs




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    stack layout in multithreadded programs  
Bahadir


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-08-07 06: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






[ Post a follow-up to this message ]



    Re: stack layout in multithreadded programs  
Frank Cusack


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-09-07 12:24 AM

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





[ Post a follow-up to this message ]



    Re: stack layout in multithreadded programs  
Bahadir


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-11-07 06: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> wro
te:
> 
> 
>
> 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






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 04:41 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register