This is the mail archive of the pthreads-win32@sources.redhat.com mailing list for the pthreas-win32 project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Memory leak in pthread_setcanceltype()?


> I don't know for a fact, but I'd be leary about calling
pthread_mutex_destroy()
> on a mutex not initialized with pthread_mutex_init() (i.e. initialied with
> PTHREAD_MUTEX_INITIALIZER).  It feels like free()ing a pointer to a char
array
> allocated on the stack to me.  I certainly wouldn't depend on calling
> pthread_mutex_destroy() on a mutex not initialized via
pthread_mutex_init() to
> be portable.

> From the sound of it, to be safe I'd personally recommend avoiding the
> PTHREAD_MUTEX_INITIALIZER and use pthread_mutex_init() to initialize and
> pthread_mutex_destroy() to destroy.

That's what I've done now and the memory leaks have gone away.  Seems fairly
sensible to me and I'm happy with this. 

My original implementation was done after reading Butenhof's "Programming
with POSIX Threads" (Addison-Wesley) which said on page 51, "You do not need
to destroy a mutex that was statically initialized using the
PTHREAD_MUTEX_INITIALIZER macro."

Thanks to all who helped,

Ally Hume


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]