Re: 256 threads maximum?
Panagiotis Issaris <[email protected]> Sat, 06 Mar 2004 01:59:57 +0100
| Newsgroups | gmane.comp.lib.phil |
|---|---|
| Message-ID | <[email protected]> |
Scott Lamb wrote: >> 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. Thanks!!! I validated your explanation, and it worked out just as you predicted! > 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. Yes, you are absolutely right. Or they could have used a 7158 byte stack on a 32-bit machine :-) Thanks for your explanation, With friendly regards, Takis