Changing the limit of maximum number of pthreads b

2019-02-06 08:12发布

问题:

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.

回答1:

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)



回答2:

Your problem is that you have not called pthread_detach on the threads in question. This tells pthread that the resources associated with each thread will be released when the thread terminates. You have to call either pthread_join or pthread_release on all threads to release thread resources. That means that you also have to call pthread_detach in your pthread_join cancellation handlers or leak.



回答3:

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...



回答4:

Look at this:

Maximum number of threads per process in Linux?

And take a look at this as it might pertain to your question:

Serve one client with each server thread