[public reply, as I think a few people might be interested in the results]
Without doing this, you will leak memory. The pthread library MUST keepQuote:>// pthread_detach (*chld_thr);
information for each thread that exits until it has been reaped, unless it
is detached. You will find the same "leaky" behavior exists on Solaris
(yes, I tried your program there).
Note also two other problems in your code. First off
But the pointer that was passed in was on the *stack*. You can't deleteQuote:> delete clt;
something from the stack like that (on my glibc6 machine, this causes a core
dump).
Secondly (and much worse, IMHO), is the fact that you passed in a stack
structure. It appears that you have omitted some code, so I will assume
what you do is fill in this stack structure with some data and then pass the
pointer in like you do. But what if the following chain of events occur?
Fill in data for thread 1.
Call pthread_create for thread 1.
Fill in data for thread 2.
Call pthread_create for thread 2.
--now, thread 1 starts running-- (yes, this is a perfectly valid happening)
--now, thread 2 starts running-- (yes, this is a perfectly valid happening)
You will note that both threads get the data meants for thread 2. Your
original idea of deleting clt is correct -- clt needs to be in the heap, not
on the stack.
Best of luck!
--randy
> I test the performance of pthreads using this code.
>I found that the program size keep increasing even if
>the thread has been stoped. Seem to be some memory leak.
>Is there anything wrong
>with my code or a bug in pthread? please give me some
>hints. Thanks!
>PS. you can use ps -fu yourusername -o vsz -o rss -o comm
>to see the size of the process.