Boost :: interprocess :: scoped_lock application crash inside

I use boost :: interprocess :: scoped_lock if the application error for some reason is not released inside the mutex scope. The next time the application runs (without restarting the computer), the mutex is locked.

How it works? I will give a simple code example 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 have finished timeout as shown below. Anyone who could come up with a solution that doesn't limit the lock time?

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();
        }
    }
+3
source share
1 answer

It seems to me completely logical :)

, , (IPC), . , !

, (), .

, . , , . , . -. , , ...

, , :)

my2c

+1

All Articles