256 threads maximum?
Scott Lamb
slamb at slamb.org
Fri Mar 5 23:13:54 UTC 2004
Panagiotis Issaris wrote:
> Hi,
>
> The following simple testprogram tries to create the number of threads
> given as argv[1].
> When I'm using a 2.6.3 kernel with glibc 2.3.2/NPTL 0.60, the maximum
> number of threads this application can create is 255. With any number
> higher it complains about memory allocation failing.
I bet you're using a 32-bit machine with an 8 MiB stack. The top bit is
reserved for kernel use, IIRC, so a program can only address 2 GiB of
virtual memory. 2 GiB / 8 MiB = 256. One thread already exists. If you ran a
$ ulimit -s 4096
$ ./thr 511
It would succeed, I'd think. And 512 would fail.
I'm not sure why LinuxThreads was able to allocate more threads. Maybe
it determines the stack size in a different way?
> What am I doing wrong? I know that NPTL can do a lot better then this,
> since I have been reading reports on NPTL creating thousands of threads
> ( I think I recall someone stating creating 300000 threads from one
> process).
You can do a little better by decreasing the stack space per thread, as
mentioned above. But I think they must have been doing this test on a
64-bit machine.
Scott
More information about the Phil-list
mailing list