|
|||||||||||
|
Re: pthreads bug - memory leak
From: Marco S Hyman <marc(at)snafu.org>
Date: Fri Jan 24 2003 - 17:01:10 EST
I enjoyed! Note for the future, attachments are stripped, send the code in line. But no need to resend this time, as I can explain the problem. Your code contains this:
pthread_mutex_t condition_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t condition_cond = PTHREAD_COND_INITIALIZER;
The problem here is that both pthread_mutex_t and pthread_cond_t are pointers and the initializer is nothing but NULL. They are not really static variables. pthreads is semi-smart in that it will allocate memory and initialize the values for you, in effect calling pthread_cond_init and pthread_mutex_init behind your back.
However, the thread code can't tell when the variables go out of scope
or are no longer being used, so it can not call pthread_mutex_destroy
or pthread_cond_destroy for you. You have to do it yourself. Adding
to the end of your tsleep subroute is necessary for proper operation. Doing that will stop unlimited growth. On an i386 running -current memory use stabilizes at 40K. // marc Received on Fri Jan 24 17:02:52 2003 This archive was generated by hypermail 2.1.8 : Wed Aug 23 2006 - 13:29:48 EDT |
||||||||||
|
|||||||||||