I use pthread_mutex_t in a C ++ program, as shown below:
class Mutex : public noncopyable { public: Mutex() { pthread_mutex_init(&m_mutex, NULL); } void acquire() { pthread_mutex_lock(&m_mutex); } void release() { pthread_mutex_unlock(&m_mutex); } private: pthread_mutex_t m_mutex; };
(The class is not copied - http://www.boost.org/doc/libs/1_53_0/boost/noncopyable.hpp )
What I do not understand is considered a mistake in order not to call pthread_mutex_destroy in the destructor? The documentation I read does not indicate that destroy should be called.
Does anyone know what pthread_mutex_destroy actually does and under what conditions is required?
EDIT
Is the answer to pthread_mutex_destroy also applicable to pthread_cond_destroy etc.? They seem to me almost useless functions, if only pthread_mutex_init et. and others allocate memory? (the documents, for me, are not entirely clear on this.)
I can not harm the so-called destruction, so the question is mostly academic.
On linux, in any case, it seems that destruction only sets the mutex to an invalid state:
int __pthread_mutex_destroy (mutex) pthread_mutex_t *mutex; { if ((mutex->__data.__kind & PTHREAD_MUTEX_ROBUST_NORMAL_NP) == 0 && mutex->__data.__nusers != 0) return EBUSY; mutex->__data.__kind = -1; return 0; }
(From glibc-2.14 / nptl / pthread_mutex_destroy.c).
c ++ pthreads posix mutex
Wayne uroda
source share