红联Linux门户
Linux帮助

Maximum 382 threads on Debian Etch?

发布时间:2008-02-06 00:01:07来源:红联作者:SMuonon
My application creates a thread when it establishes a call. When I run the program on Debian Etch, it always fall on the 382th pthread-create() with an error code 12 (out of memory).

I was so suspecting that I have some memory leaks somewhere. After wrapping all mallocs, I decide that I don't.

Now I have to look into pthread functions and it turns out we need to inform the thread to release its resource when it is terminated. One of the function to use is: pthread_detach(), which indicates to the implementation that storage for the thread can be reclaimed when the thread terminates.

It's good to have the problem solved. But when you think it over, does it mean I can only run 382 concurrent threads on the system?

Here is a good procedure to diagnose the problem:

with ps -eLf you can see processes with their threads (under LWP (light weight process))
look in /proc/sys/kernel/threads-max (max number of threads for the whole system)
try with pthread_detach() for each thread

And, remember the magic number of 382 (for Etch). Each thread takes some resource, if we don't tell the thread to release the resource when we terminate it, it does not.
文章评论

共有 0 条评论