How can I maximize the number of threads ?

A program that can creates number of threads depends upon the available virtual memory, Whenever each threads is created one stack is allocated to the thread generally each stack in linux and windows takes 1MB stack size.

while Linux restrict the number of process and number of maximum threads can be look in to :

cat /proc/sys/kernel/threads-max 

and default is the number of threads is the memory pages/4 .

So total number of threads in a linux system can be calculated as below

number of threads = total virtual memory / (stack size*1024*1024)

So it conclude that number of threads can be increased by either increasing virtual memory or decreasing by stack size. But we can’t decreased stack size too much other wise we face stack overflow issue

420 total views, 10 views today

Leave a Reply