c++ - WaitForSingleObject() not returning WAIT_ABANDONED -
i have mfc application. in initinstance() created named mutex , acquiring calling waitforsingleobject(). in exitinstance() mutex released.
bool cmyapp::initinstance() { m_hmutex = createmutex( null, false, "myappmutex" ); dword dwres = waitforsingleobject( m_hmutex, infinite ); switch( dwres ) { case wait_abandoned: break; case wait_object_0: break; } } bool cmyapp::exitinstance() { ::releasemutex( m_hmutex ); ::closehandle( m_hmutex ); }
what understand mutex documentation if process exits out releasing acquired mutex, when process tries acquire waitforxxxobject() return wait_abandoned.
for testing ran application , killed using task manager releasemutex wont called. when ran application again waitforsingleobject() in initinstance() returns wait_object_0. expected behavior?
from msdn page on createmutex
:
the system closes handle automatically when process terminates. mutex object destroyed when last handle has been closed.
it true mutex in abandoned state when terminate process, 2nd sentence tells mutex won't exist anymore if terminated process opened it.
when re-launch application, recreate new mutex because no other process had handle it.
Comments
Post a Comment