Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - pthread_create API failing with EAGAIN: (6 Items)
   
pthread_create API failing with EAGAIN  
I have a process that is able to create only 41 Threads. Attempt to create any other thread results in failure with eror
 code EAGAIN.  

To the best of my knowledge ( there could be exceptions I am not aware of ) all threads are created dettached. 

The problem is immediately reproducible as soon as the process comes up. So I am not suspecting any memory leak .

The number of threads that can be created reduces as the code size of the process increases. 

The process has 10 MB of code size 3.6 MB of data and 47 threads amounting to 132K each (6.2 Mb). This adds of to approx
 20 MB.

The process is running on ARM 7. QNX version 6.3.0. The virtual address space for a process is restricted to 32 M. So I 
assume that I have 12 MB approx of virtual address space available.

What could be the reason that I am unable to create more threads, even though I have 12 MB of virtual address space 
remaining?

I am attaching the pidin mem dump of the process here
Attachment: Text pidin.txt 7.56 KB
AW: pthread_create API failing with EAGAIN  
Not all of the in total available 32MB per process address space is usable for all kind of mappings.
Referring to the 6.4.1 documentation http://www.qnx.com/developers/docs/6.4.1/neutrino/prog/arm_memory.html
you see that the 32MB are diveded into different regions
used for different kind of mapping types.
6.3.0 documenation does not show this, but I am sure that this kind of separation is also done in 6.3.0

HTH
/hp

<snippet>
This mechanism imposes a number of restrictions:

    * Each process address space is limited to 32 MB in size. This space contains all the code, data, heap, thread 
stacks and shared objects mapped by the process. The virtual address space is allocated as follows:
      Range: 	Used for:
      0- 1 MB 	Initial thread stack
      1-16 MB 	Program text, data, and BSS
      16-24 MB 	Shared libraries
      24-32 MB 	MAP_SHARED mappings

      When a program is loaded, the loader will have populated the stack, text, data, BSS, and shared library areas.

      If you allocate memory, malloc() tries to find a free virtual address range for the requested size. If you try to 
allocate more than 15 MB, the allocation will likely fail because of this layout. The free areas are typically:
          o approximately 15 MB (addresses between 1 MB + sizeof(text/data/heap) and the 16 MB boundary)
          o approximately 7 MB (addresses between 16 MB + sizeof(shared libs) and the 24 MB boundary)
          o approximately 8 MB (addresses between 24 MB + sizeof(MAP_SHARED mappings) and the 32 MB boundary)

</snippet>


>-----Ursprüngliche Nachricht-----
>Von: Christian Scheuch [mailto:community-noreply@qnx.com] 
>Gesendet: Donnerstag, 10. Juni 2010 09:27
>An: ostech-core_os
>Betreff: pthread_create API failing with EAGAIN
>
>I have a process that is able to create only 41 Threads. 
>Attempt to create any other thread results in failure with 
>eror code EAGAIN.  
>
>To the best of my knowledge ( there could be exceptions I am 
>not aware of ) all threads are created dettached. 
>
>The problem is immediately reproducible as soon as the process 
>comes up. So I am not suspecting any memory leak .
>
>The number of threads that can be created reduces as the code 
>size of the process increases. 
>
>The process has 10 MB of code size 3.6 MB of data and 47 
>threads amounting to 132K each (6.2 Mb). This adds of to approx 20 MB.
>
>The process is running on ARM 7. QNX version 6.3.0. The 
>virtual address space for a process is restricted to 32 M. So 
>I assume that I have 12 MB approx of virtual address space available.
>
>What could be the reason that I am unable to create more 
>threads, even though I have 12 MB of virtual address space remaining?
>
>I am attaching the pidin mem dump of the process here
>
>
>
>_______________________________________________
>
>OSTech
>http://community.qnx.com/sf/go/post56485
>
Re: AW: pthread_create API failing with EAGAIN  
I tried to create a test program, that only creates threads ( each thread immediately goes to sleep). On executing it on
 the same platform, it spawned 241 threads each having stack size of 132k.
This amounts to 241*132 K used for the stack = 31.8 MB

Hence, in this case almost the complete 32 MB of vritual memory could be used for stack.

Am I missing something here? 
Re: AW: pthread_create API failing with EAGAIN  
Please ignore my previous post. It was a misunderstandign from my side.
You were correct hans.  The virtual address space is exhausted when probably heap is being allocated for  the new 
threads


Thanks
RE: AW: pthread_create API failing with EAGAIN  
Most likely you are losing virtual space for the thread stacks.  The
default size for each stack is 132k. Try using
pthread_attr_setstacksize() to set a smaller stack size for the created
threads.

David 

> -----Original Message-----
> From: Christian Scheuch [mailto:community-noreply@qnx.com] 
> Sent: June 10, 2010 9:08 AM
> To: ostech-core_os
> Subject: Re: AW: pthread_create API failing with EAGAIN
> 
> Please ignore my previous post. It was a misunderstandign 
> from my side.
> You were correct hans.  The virtual address space is 
> exhausted when probably heap is being allocated for  the new threads
> 
> 
> Thanks
> 
> 
> 
> _______________________________________________
> 
> OSTech
> http://community.qnx.com/sf/go/post56505
> 
> 
Re: RE: AW: pthread_create API failing with EAGAIN  
Hi,

I tried to reduce the maximum stack size to 32K and the number of threads that could be created in the process increased
. So Indeed the virtual address space of the process was getting exhausted.

Thanks.