boostorg / interprocess

Boost.org interprocess module
http://boost.org/libs/interprocess
134 stars 117 forks source link

Problem with managed_shared_memory on Windows with fast startup #216

Closed Trigve closed 6 months ago

Trigve commented 6 months ago

I'm using boost 1.80.0, x86, MSVC 2019 C++20 mode on Windows 10.

I've a service process (1), that is using boost.interprocess managed_shared_memory for storing some global data using this code:

boost::interprocess::managed_shared_memory{boost::interprocess::create_only,
    shm_name.c_str(),
    4 * 1024
}

The service is started during the windows start. Then another process (2) is reading this shared memory data using this code:

boost::interprocess::managed_shared_memory{boost::interprocess::open_only,
    shm_name.c_str()
}

The problem is, that when the Windows is shut down/started using "fast startup" mode, then when the process (2) is started, it cannot find the shared memory by the given name. Because on Windows the managed_shared_memory is emulated using files (AFAIK), when I look at the given location on file system where the shared memory is "stored", it's name doesn't correspond to the one, that is set during creation. It looks like the fast startup is somehow messing with it.

igaztanaga commented 6 months ago

I don't think there is a bug here. Shared memory should not be visible between startups (fast or otherwise). If you want data to persist, use memory mapped files (managed_mapped_file) . In fact, quite a bit effort was put so that shared memory from previous boot is not visible in the current boot.

Trigve commented 6 months ago

Thank you for the reply, I see now. I didn't find anything regarding the "Shared memory should not be visible between startups (fast or otherwise)" in the documentation so was under impression it is bug.