Boost :: interprocess :: named_mutex vs CreateMutex

I want to switch from CreatMutexto boost::interprocess::named_mutexto limit my application to one instance. Both methods work when the application runs and ends just fine. However, the lock does not open when the application crashes and is used boost::interprocess::named_mutex. I could solve this problem using two name_mutex methods, but I do not understand this problem.

Why is the lock for boost::interprocess::named_mutexnot released when the application crashes, but is it a release from CreatMutex? Who cares?


boost::interprocess::named_mutex mutex(boost::interprocess::open_or_create, "my_mutex");
boost::interprocess::scoped_lock<boost::interprocess::named_mutex> lock(mutex, boost::interprocess::try_to_lock);
if(!lock) {
    return 1; //exit
}
//application may crash here.
boost::interprocess::named_mutex::remove("my_mutex");
return 1; //exit
+5
source share
2 answers

: boost::interprocess, - . , API Windows, ...


- , .

boost::interprocess::named_mutex, , , . (. 1) ( , Boost 1.54.0)... , Common Application Data (. 2). . , ... , , , , .

, CreateMutex, , . Mutex, , , CloseHandle . mutex , .

:

, . mutex , .

, Windows .

, ReleaseMutex, , , / , , (WaitForSingleObject WAIT_ABANDONED) .

, , , , -.


  • , - SHGetKnownFolderPath. .

  • %ALLUSERSPROFILE%\Application Data\boost.interprocess ProgramData\boost.interprocess, - .

+7

, , , interprocess_mutex .

, , , / (...). , , ( ). , .

, (, ) . , , , , , .

+1

All Articles