Bug 108703 - 304 pthreads per process limit
304 pthreads per process limit
Product: Red Hat Enterprise Linux 3
Classification: Red Hat
Component: kernel (Show other bugs)
i686 Linux
medium Severity medium
: ---
: ---
Assigned To: Arjan van de Ven
Brian Brock
Depends On:
  Show dependency treegraph
Reported: 2003-10-31 07:06 EST by Need Real Name
Modified: 2007-11-30 17:06 EST (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2003-10-31 07:51:46 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

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

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 *);
   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);
         printf("Unable to create thread. Failed at %d\n", i);
   printf("Any key to exit\n");
void *threadfunc(void * arg)
    // sleep for a while

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

How reproducible:

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

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

[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 07:43:28 EST
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 07:51:46 EST
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.