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

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -