[interprocess] Sharing shared_memory_object across processes?

I either do not understand what I am seeing, or I may have stumbled upon a bug, at least in a Windows environment. Or, of course, my expectations may be unrealistic. The short of this is that when I create a boost::interprocess::shared_memory_object that isn't removed for the duration of the program's run, the reading program's run can't seem to open the shared_memory_object, despite creating a boost::interprocess::permissions object and calling 'set_unrestricted()'. I get an exception indicating that access is denied. If nothing else, the code I've provided is an interprocess version of the classic read-writer's problem, second version (writers preferred). It may be of use to someone with a little cleaning. Environment: Compiler: MSVC++ 10 OS: Win 7 Pro, 64-bit. Steps to reproduce: 1. In VC++ 10, create an empty command-line project. 2. Replace contents of your .cpp with the code in this e-mail. 3. Compile. 4. Run the executable twice, first with an argument, next without. Expected results: The executable run without arguments indicates how much data was transferred on the same line. Actual results: The executable run without arguments complains that access is denied. NOTE: If you #define BOLD_NEW_TEST and recompile, this program runs according to expectations. This causes the objects to be compiled in a way where the shared_memory_objects only last for as long as it takes to write or read the data. I suspect this shouldn't be necessary, but perhaps I'm wrong. The error is especially peculiar to me, as I can open the file itself with a text editor. It doesn't seem like it should be denied. - Trey

El 25/04/2012 20:26, Joseph Van Riper escribió:
I either do not understand what I am seeing, or I may have stumbled upon a bug, at least in a Windows environment. Or, of course, my expectations may be unrealistic.
thanks for the report, I'll try to see what's happening. Ion

El 25/04/2012 20:26, Joseph Van Riper escribió:
I either do not understand what I am seeing, or I may have stumbled upon a bug, at least in a Windows environment. Or, of course, my expectations may be unrealistic.
The short of this is that when I create a boost::interprocess::shared_memory_object that isn't removed for the duration of the program's run, the reading program's run can't seem to open the shared_memory_object, despite creating a boost::interprocess::permissions object and calling 'set_unrestricted()'. I get an exception indicating that access is denied.
Sorry, but in your test the reader deletes mutexes in use and creates them again with the same name. This means that the writer and the reader don't shared the same mutex! Regarding permissions, I think there is a problem in the function "unlink_file" of boost/interprocess/detail/win32_api.hpp. It seems that trying to to do a "normal" delete is not a good idea for already unrestricted permission files so please comment "if(!delete_file(filename)){" condition. Let's see if this helps a bit. Best, Ion

2012/4/26 Ion Gaztañaga <igaztanaga@gmail.com> Sorry, but in your test the reader deletes mutexes in use and creates them
again with the same name. This means that the writer and the reader don't shared the same mutex!
Ah, I misunderstood the behavior of ::remove(). I think I wrongly assumed the file would not be removed if the mutex and shared_memory_object was in use. I am not sure what lead me to think that, as logically, the behavior you describe makes sense. Humm... if I remove all the ::remove() calls (even for the shared_memory_object) from both the reader and writer code, this works without any changes to interprocess, and I can safely start and stop either reader or writer process at any point, in any order. That's the behavior I want. I suppose I'll need to resort to some other kind of mechanism for ensuring the memory mapped files (shared memory and mutexes) are removed should all processes using these objects stop running. Even with your suggested changes, I haven't figured out how to remove the files safely. Many thanks for the help here, Ion.
participants (2)
-
Ion Gaztañaga
-
Joseph Van Riper