Skip to content

Instantly share code, notes, and snippets.

@nglee
Last active September 24, 2018 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nglee/a03ed8c2de387608f6d9d98ce53beb51 to your computer and use it in GitHub Desktop.
Save nglee/a03ed8c2de387608f6d9d98ce53beb51 to your computer and use it in GitHub Desktop.
Persistence of interprocess_mutex
#include <boost/interprocess/managed_xsi_shared_memory.hpp>
#include <boost/interprocess/xsi_key.hpp>
#include <iostream>
using namespace boost::interprocess;
int main()
{
managed_xsi_shared_memory *shm = nullptr;
try {
shm = new managed_xsi_shared_memory{ open_or_create, xsi_key("bitest2.cpp", 239), 1024 };
} catch (interprocess_exception& e) {
std::cout << e.what() << std::endl;
std::cout << "managed_xsi_shared_memory open_or_create fail" << std::endl;
}
try {
interprocess_mutex *mtx = shm->construct<interprocess_mutex>("gMutex")();
if (mtx)
std::cout << "interprocess_mutex create success" << std::endl;
else
std::cout << "interprocess_mutex create fail" << std::endl;
} catch (interprocess_exception& e) {
std::cout << e.what() << std::endl;
std::cout << "interprocess_mutex create fail" << std::endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment