number of threads = total virtual memory / (stack size*1024*1024)
Thus, the number of threads per process can by increasing total virtual memory or by decreasing stack size. Decreasing stack size can lead to code failure due to stack overflow while max virtual memory is equal to the swap memory.
Check you machine:
Total Virtual Memory:
ulimit -v (default is unlimited, thus you need to increase swap memory to increase this)
Total Stack Size:
ulimit -s (default is 8Mb)
Command to increase these values:
ulimit -s newvalue
ulimit -v newvalue
replace new value with the value you want to put as limit.
How to increase swap memory?