Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

Re: pthreads bug - memory leak

From: Marco S Hyman <marc(at)snafu.org>
Date: Fri Jan 24 2003 - 17:56:37 EST


I wrote...

> or pthread_cond_destroy for you. You have to do it yourself. Adding

After some discussion and thought I agree that the above should not be necessary, and might even be considered wrong (even though it is required to not leak memory in the current implementation).

I now consider this operation a design flaw in the current code. As our code is based upon the FreeBSD code I'm not surprised that they have the same issue.

Theis problem exists in ALL statically allocated pthread types. It will take a while to correct this and verify the code after correction. In the mean while the only thing I can recommend is to NOT use static allocation of pthread types. This will make the code portable, if nothing else.

Replace, for example:

        pthread_mutex_t condition_mutex = PTHREAD_MUTEX_INITIALIZER;
	...
        pthread_mutex_lock( &condition_mutex );
	...
        pthread_mutex_unlock( &condition_mutex );

with

	pthread_mutex_t condition_mutex;
	...
	pthread_mutex_init(&condition_mutex);
	pthread_mutex_lock(&condition_mutex);
	...
        pthread_mutex_unlock(&condition_mutex);
	pthread_mutex_destroy(&condition_mutex);

// marc Received on Fri Jan 24 17:58:57 2003

Do you need help?X

This archive was generated by hypermail 2.1.8 : Wed Aug 23 2006 - 13:29:48 EDT


Contact Us  Legal Notices  Order Services Online 
Pantek Home  Privacy Policy  IT news  Site Map  Pantek Library