I'm using boost::interprocess::scoped_lock, if the application crash for some reason inside the scope the mutex isn't released. Next time the application is executed (without restarting the computer), the mutex is locked.
How's this intended to work? I give a simple example of the code below.
{
boost::interprocess::named_mutex lockMutex(boost::interprocess::open_or_create, "lockName");
boost::interprocess::scoped_lock<boost::interprocess::named_mutex> lock(lockMutex);
//crash here
}
I ended up doing a timeout like below. Anyone who could come up with a solution that doesn't limit the time for lock?
boost::interprocess::named_mutex named_mtx(boost::interprocess::open_or_create, lockName.c_str());
while(true)
{
if(named_mtx.try_lock())
{
break;
}
if(!named_mtx.timed_lock(boost::get_system_time() + boost::posix_time::milliseconds(TIMEOUT_MILLISECONDS)))
{
named_mtx.unlock();
}
}