Is it possible by any means to change the limit on the number of pthreads a process can create ? Currently on my linux system I can create around 380 threads but I want to increase that to say as long as memory is available.
Thus, the number of threads per process can be increased by increasing total virtual memory. The amount of stack size per thread is more likely to be the limit than anything else. Reducing the per-thread stack size is also a way to increase the total number of threads.
You can control the maximum number of threads using the thread-max kernel parameter. “file /proc/sys/kernel/threads-max” defines this parameter. Using the “cat” command, you can view this file. Here, the output 45444 shows the maximum 45444 threads the kernel can execute.
Thread Limits Because each thread consumes part of a process's address space, processes have a basic limit on the number of threads they can create that's imposed by the size of their address space divided by the thread stack size.
The scheduling policy can either be SCHED_FIFO or SCHED_RR. FIFO is a first come first serve policy. RR is a round robin policy that might preempt threads.
reduce user's stack size 'ulimit -s 1024
';
default: 8MB
reduced: 1MB
to increase number of threads.
set the stack size: pthread_attr_setstacksize(1024)
cat /proc/sys/kernel/threads-max
may work in Linux but not other UNIX systems. I thought the right way is
Maximum number of threads per process - sysconf(_SC_THREAD_THREADS_MAX) failing
which works on some UNIX systems (like HPUX) but not on Solaris or Linux...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With