Bug 108703 - 304 pthreads per process limit
Summary: 304 pthreads per process limit
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 3
Classification: Red Hat
Component: kernel
Version: 3.0
Hardware: i686
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Arjan van de Ven
QA Contact: Brian Brock
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2003-10-31 12:06 UTC by Need Real Name
Modified: 2007-11-30 22:06 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2003-10-31 12:51:46 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Need Real Name 2003-10-31 12:06:22 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030922
Epiphany/1.0.1

Description of problem:
There seems to be a limit of 304 pthreads that can be created for a single
process.  The problem also occurs on 2.1 with a limit of 254 threads.

This can be demonstrated with the following code:



[dturner@localhost tmp]$ cat MaxThread.c
 
 
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <sys/types.h>
 
void *threadfunc(void *);
 
 
main()
{
   int i, t;
   pthread_t thread;
    
   printf("Starting threads\n");
    
 
   for (i=0; i< 2000; i++)
   {
      t = pthread_create(&thread, NULL, threadfunc, NULL);
      if (t == 0)
         printf("created thread %d\n", i);
      else
      {
         printf("Unable to create thread. Failed at %d\n", i);
         break;
      }
   }
   sleep(1);
   printf("Any key to exit\n");
   getchar();
   exit(0);
}
 
 
 
void *threadfunc(void * arg)
{
    // sleep for a while
    sleep(10);
}


Version-Release number of selected component (if applicable):


How reproducible:
Always

Steps to Reproduce:
1. gcc -lpthread -D_REENTRANT -o MaxThread MaxThread.c
2. ./MaxThread
    

Actual Results:  [dturner@localhost tmp]$ ./MaxThread
Starting threads
created thread 0
...
created thread 303
created thread 204
Unable to create thread. Failed at 205
Any key to exit

Additional info:

[david@localhost tmp]$ ulimit
unlimited

[david@localhost tmp]$ cat /proc/sys/kernel/threads-max
1000000


[dturner@localhost tmp]$ cat /proc/meminfo
        total:    used:    free:  shared: buffers:  cached:
Mem:  393404416 382902272 10502144        0 19243008 237506560
Swap: 1076051968  5435392 1070616576
MemTotal:       384184 kB
MemFree:         10256 kB
MemShared:           0 kB
Buffers:         18792 kB
Cached:         228304 kB
SwapCached:       3636 kB
Active:         242104 kB
ActiveAnon:     111444 kB
ActiveCache:    130660 kB
Inact_dirty:         0 kB
Inact_laundry:  106696 kB
Inact_clean:      5084 kB
Inact_target:    70776 kB
HighTotal:           0 kB
HighFree:            0 kB
LowTotal:       384184 kB
LowFree:         10256 kB
SwapTotal:     1050832 kB
SwapFree:      1045524 kB
HugePages_Total:     0
HugePages_Free:      0
Hugepagesize:     4096 kB

Comment 1 Jakub Jelinek 2003-10-31 12:43:28 UTC
More interesting is what ulimit -s shows. If it prints unlimited, then
default thread stack size is 8MB, otherwise it is the specified value
(unless pthread_attr_setstacksize etc. are used).
With 8MB thread stacks you run out of virtual memory really soon.

Comment 2 Need Real Name 2003-10-31 12:51:46 UTC
That'll be it then.  I have reduced the stack size and demonstrated that this is
not a bug.  Thank you.


Note You need to log in before you can comment on or make changes to this bug.