I am trying to develop a dll plugin for a third party application which reads data generated by another exe. I am using boost::managed_windows_shared_memory
for this.
The exe creates the shared memory and writes an object to it which is working fine. However, when I try to find that object in the dll code my the 3rd party app crashes. I searched a lot and came across this post. The last answer mentions that using find() creates a deadlock.
I tried using boost::interprocess_mutex
but it didn't work either. Any guidelines on how I can fix this? Thanks!
In the exe:
boost::interprocess::interprocess_mutex myMutex;
myMutex.lock();
i = managed_shm.find_or_construct<int>("MyInteger")(992);
myMutex.unlock();
In the dll :
boost::interprocess::interprocess_mutex myMutex;
myMutex.lock();
std::pair<int*, std::size_t> p = managed_shm.find<int>("MyInteger");
myMutex.unlock();
The interprocess (anonymous) is intended to used, when placed inside shared memory. If you want to use it to govern the creation of the shared-memory area or to synchronize the access to it from outside the shared memory, use a named mutex: