Symantec Interview Question
AssociatesCountry: India
Interview Type: In-Person
There is no particular limit for no of threads inside a process till you have available memory.If you have memory then you can create as many threads you want.Take the example off a web server it can create as many threads it wants according to the number of users it is serving. So as per my view it depends on the memory limitations.
Number of threads in a process is dependent on the virtual memory available in the system and the stack size. The approximate number of threads possible in a process can be calculated by using following formula:
Virtual memory = Physical RAM + swap memory
Number of threads = (virtual memory)/stack-size for a process.
The stack size that a process can have can be obtained using following command:
ulimit -s
The above theory comes from the fact that every thread in the process shares process resources except they have their own set of registers and stack. They share the process address space, which includes code segment, data segment, process heap. In case stack size is increased then total number of thread which can exist simultaneously in a process will decrease and if we try to create more threads then the thread creation api (like pthread_create) returns error (EAGAIN ) to indicate that no more resource (memory to allocate stack) is available in the system.
There is no limitation of the number of threads per process.however there is a limitation of the total number of threads created. If your OS is linux(or like), you can see the number:
- notbad September 18, 2012cat /proc/sys/kernel/threads-max