Sindhur Kumar
Sindhur Kumar

Reputation: 31

Regarding threads in Linux

How many threads a single process can handle in Linux(RHEL-5)? Once threads are created how much stack an each thread can get ?

Upvotes: 3

Views: 1857

Answers (4)

MarkR
MarkR

Reputation: 63538

If you're on a 32-bit machine, then the thread stacks will consume the address space eventually, depending on the size, probably at < 10,000 threads.

10k threads is certainly feasible and some people do run production servers with that many, but you really want to be sure that's the best way of doing what you're doing.

If you're thinking of having 10k threads, you probably have 64-bit machines anyway, and lots and lots of ram.

Upvotes: 1

almathie
almathie

Reputation: 731

There is not a maximum number of threads by process.

There is however limit of the total active thread. This value can be retrieved by typing :

cat /proc/sys/kernel/threads-max

you can also change this value :

echo 99999 > /proc/sys/kernel/threads-max

Hope this helps.

Upvotes: 1

Aaron Digulla
Aaron Digulla

Reputation: 328594

Maximum number of threads: Maximum number of threads per process in Linux?

Stack size:

Even if pthread_attr_setstacksize() and pthread_attr_setstackaddr() are now provided, we still recommend that you do not use them unless you really have strong reasons for doing so. The default stack allocation strategy for LinuxThreads is nearly optimal: stacks start small (4k) and automatically grow on demand to a fairly large limit (2M). Moreover, there is no portable way to estimate the stack requirements of a thread, so setting the stack size yourself makes your program less reliable and non-portable.

(from http://pauillac.inria.fr/~xleroy/linuxthreads/faq.html)

Upvotes: 3

Drakosha
Drakosha

Reputation: 12155

Thread stack size is configurable, using pthread_attr_setstack method. Amount of thread is imho limited only by resources you have, more than 2K threads work in an application i know.

Upvotes: 0

Related Questions