[PATCH] Return EAGAIN if allocate stack error when creating thread

Mike Frysinger vapier at gentoo.org
Wed Dec 21 14:27:52 UTC 2005


On Wed, Dec 21, 2005 at 05:01:49PM +0800, Jie Zhang wrote:
> On 12/21/05, Mike Frysinger <vapier at gentoo.org> wrote:
> > On Wed, Dec 21, 2005 at 11:00:06AM +0800, Jie Zhang wrote:
> > > This is a patch for libpthread/linuxthreads.old. When used for uClinux
> > > on nommu processor, allocating a large stack for thread is likely to
> > > fail. However, pthread_handle_create () does not check the return
> > > value of pthread_allocate_stack () to see if stack is successfully
> > > allocated. This patch makes pthread_handle_create () return EAGAIN
> > > immediately if the stack cannot be allocated.
> >
> > why does it need to be immediately ?  the code is executed in a loop
> > and if a the allocate stack continues to fail, it will return EAGIN
> 
> I think the loop was written for MMU case. When there is MMU, mmap ()
> is used to allocate the stack. If one segment is already mapped, we
> should continue to see if we can use the next one. However, for NOMMU,
> malloc () is used. It's waste of CPU cycles to continue to try if it
> fails. Here is a new patch, which makes this change only for NOMMU.

ok, that makes sense ... best to include this comment in the patch then
so someone down the line doesnt scratch their head and wonder why it's
needed :)
-mike



More information about the uClibc mailing list