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 answers class 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

Popular posts from this blog

maven fortify plugin : Unable to load build session with ID XXXXX .. See log file for more details -

c# - Primavera WebServices does not return any data -

android - Display emoji panel with genymotion - keyboard/touch input? -