I'm writing a Windows application, which needs to share some date between multiple instances (processes). I choose to use boost interprocess. After some investigation, I find managed_windows_shared_memory is best for my situation. But 2nd process can't open shared memory created by 1st process.
Code for 1st instance:
#include <boost/interprocess/managed_windows_shared_memory.hpp>
using namespace boost::interprocess;
typedef boost::interprocess::managed_windows_shared_memory SharedMemory;
SharedMemory sharedMemory(create_only, "MyTestSharedMemory", 65535);
Code for 2nd instance:
#include <boost/interprocess/managed_windows_shared_memory.hpp>
using namespace boost::interprocess;
typedef boost::interprocess::managed_windows_shared_memory SharedMemory;
try
{
SharedMemory sharedMemoryT(open_only, "MyTestSharedMemory");
}
catch (interprocess_exception &ipce)
{
if (ipce.get_error_code() == not_found_error)
{
::OutputDebugStringA("Not found");
}
}
I'm sure when 2nd instance trying to open the shared memory, 1st instance process is still running (not exited).
By running accesschk.exe, I'm sure the shared memory system object is created and still exiting when 2nd instance trying to open it. Here is the output about this shared memory. Here "my-domain", "my-account" and "my-domain-account" have actual values in my environment.
\Sessions\5\BaseNamedObjects\MyTestSharedMemory
Type: Section
Medium Mandatory Level (Default) [No-Write-Up]
RW NT AUTHORITY\SYSTEM
SECTION_ALL_ACCESS
RW my-domain\my-account
SECTION_ALL_ACCESS
RW my-domain\my-domain-account
SECTION_ALL_ACCESS
Every time, 2nd instance gets "not_found_error". If I try to create shared memory first and then try to open it in same instance, it successes. Any idea? I'm on Windows 8.1.
More information. These two instances run in same session with same user account.
I tried to use Windows API CreateFileMapping in 1st instance and OpenFileMapping in 2nd instance, it works well!
I also tried to use boost managed_shared_memory instead of managed_windows_shared_memory, it also works.
Then I tried to use boost windows_shared_memory, 1st instance create it successfully, but 2nd instance can't find it.
Looks like there is some problem in boost native windows shared memory classes (managed_windows_shared_memory/windows_shared_memory).