Operating System - HP-UX
1753597 Members
6560 Online
108796 Solutions
New Discussion

Re: pthread cleanup not happening?

 
Trygve Isaacson
Occasional Contributor

pthread cleanup not happening?

Hi, I am using pthreads on HP-UX 11i PA-RISC with the latest (I believe) pthreads-related patch PHCO_30544 installed, compiling with gcc 3.4.3 and -lpthread. I am running exactly into the limit established by the max_thread_proc kernel parameter, but this is acting as a cumulative limit, even though most of the threads have terminated.

What I mean is this. Say max_thread_proc is 200. The first 200 calls to pthread_create succeed. Meanwhile, suppose 190 of the threads have finished and exited cleanly by returning normally from their thread main function over the course of a couple of minutes. Nevertheless, the 201st call to pthread_create will return an error, even if I only have 10 threads still running, and the most I ever had running at one time was 15.

It feels as though it is not "cleaning up" the finished threads, hence reaching the configured limit of threads per process. But my experience with pthreads on other platforms is that if the thread returns cleanly from the thread main function, that is the correct way for the thread to end cleanly. So I ought to be far below the limit, because I only have a handful of threads running at any moment.

Thanks for any help,
Trygve
1 REPLY 1
Trygve Isaacson
Occasional Contributor

Re: pthread cleanup not happening?

The problem was that the code was not detaching the non-joined threads. So, these threads were "leaking" their implementation storage.