c++ - Is it good practice to lock a pthread mutex before destroying it? -
c++ - Is it good practice to lock a pthread mutex before destroying it? -
this question has reply here:
lock mutex of object before destroy deallocate memory or other unexpected 2 answersclass aaa { ... ~aaa() { pthread_mutex_lock( &m_mutex ); pthread_mutex_destroy( &m_mutex ); } }
question> saw code somewhere in project. practice so? or undefined behavior lock mutex before destroying it?
it strikes me utterly terrible practice.
from http://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_mutex_destroy.html
it shall safe destroy initialized mutex unlocked. attempting destroy locked mutex results in undefined behavior.
so code guarantees undefined behavior , needs fixed.
c++ pthreads
Comments
Post a Comment