This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Initializing initial bottom of stack variable in pthread.c


So the bottom of stack variable needs to be set to
STACK_SIZE for the thread manager + 2 * STACK_SIZE - 1
for the initial thread from the top of the stack (for
a total of 3 * STACK_SIZE - 1)?

We are using Snapgear's distribution (uClinux 2.4.31).
 We are seeing the bottom of stack variable set to 3 *
STACK_SIZE from the top of stack.  When the first
worker thread runs, it is getting allocated space in
the range of the 3 * STACK_SIZE - 1.  It's space is
actually from 2 * STACK_SIZE to 3 * STACK_SIZE - 1
from the top of initial thread's stack, so it is in
the space covered by the bottom of initial thread. 
When the close function calls pthread_self(), which
looks at current stack pointer is checked against the
initial thread bos variable.  When the very first
worker thread closes, the stack pointer is greater
than the initial bottom of stack variable, so the
close thinks that the initial thread needs to be
closed, instead of the first worker thread.  It looks
like the bottom of stack variable is set to more than
what was allocated for the manager and initial thread,
so is this a linuxthreads problem in glibc, or is it a
problem with the stack space that is getting assigned
by the kernel?

Thanks

Jay


The else if (sp >= __pthread_manager_thread_bos is
evaluating to true when we close the first worker
thread.

static inline pthread_descr thread_self (void)
{
#ifdef THREAD_SELF
  return THREAD_SELF;
#else
  char *sp = CURRENT_STACK_FRAME;
  if (sp >= __pthread_initial_thread_bos)
    return &__pthread_initial_thread;
  else if (sp >= __pthread_manager_thread_bos)
    return &__pthread_manager_thread;
  else if (__pthread_nonstandard_stacks)
    return __pthread_find_self();
  else
#ifdef _STACK_GROWS_DOWN
    return (pthread_descr)(((unsigned long)sp |
(STACK_SIZE-1))+1) - 1;
#else
    return (pthread_descr)((unsigned long)sp &~
(STACK_SIZE-1));
#endif
#endif
}

--- Daniel Jacobowitz <drow@false.org> wrote:

> On Fri, Jul 28, 2006 at 03:08:32PM -0700, Jay
> anonymous wrote:
> > I downloaded glibc-linuxthreads-2.3.6.tar.gz and
> took
> > a look at the __pthread_initial_thread_bos
> variable in
> > pthread_initialize for the case when the stack
> grows
> > down (line 534).  My first question is why is is
> it
> > initializing for at least STACK_SIZE bytes below
> the
> > current stack address?  Is this to account for the
> > stack for the initial thread & the stack for the
> > manager thread?  My second question is why the 2 *
> > STACK_SIZE in the computation?  Since the stack is
> > growing down and the computation consists of the &
> > ~(STACK_SIZE - 1), this actually initializes the
> > variable to 3 * STACK_SIZE from the top.  Is this
> > correct?
> 
> No, this allocates STACK_SIZE for the manager thread
> and then
> _at least_ STACK_SIZE for the initial thread.  Could
> be up to
> 2 * STACK_SIZE - 1, but will be at least as big as
> requested.
> 
> -- 
> Daniel Jacobowitz
> CodeSourcery
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]