[interprocess] trouble porting from boost.shmem
Hello! I'm having trouble porting my application from boost.shmem to boost.interprocess. Here are my typedefs: //-------------------- typedef std::pair< const int, MyNode> MyPair; typedef boost::interprocess::allocator < MyPair, boost::interprocess::managed_shared_memory::segment_manager> MyAlloc; typedef boost::interprocess::multimap< const int, MyNode, std::less<const int>, MyAlloc> MyMap; typedef MyMap::iterator MyMapIterator; //-------------------- In the first process I do: //-------------------- boost::interprocess::shared_memory_object::remove(SEGMENT_NAME); boost::interprocess::managed_shared_memory segment(boost::interprocess::create_only, SEGMENT_NAME, SEGMENT_SIZE); MyAlloc myAlloc(segment.get_segment_manager()); std::less<const int> myComparator; MyMap* myMap = segment.construct<MyMap>(MAP_NAME)(myComparator, myAlloc); //-------------------- In the second process I do: //-------------------- boost::interprocess::managed_shared_memory segment(boost::interprocess::open_only, SEGMENT_NAME); MyMap* myMap = segment.find<MyMap>(MAP_NAME).first; MyMapIterator it = myMap->begin(); // <- CRASHES HERE! for ( ; it != myMap->end; it++) { //... } //-------------------- The myMap pointer in the second process is not NULL, it has the same value as in the first process. Everything worked fine with boost.shmem. Anybody got a clue, what is wrong here and what is so different between how boost.shmem and boost.inteprocess perform these operations? Can boost.shmem and boost.interprocess coexist? If I'm stuck with boost.shmem for storing the map in shared memory, can I still use an upgradable mutex from boost.interprocess? Thanks, Szilard
Hello!
Hi,
I'm having trouble porting my application from boost.shmem to boost.interprocess. Here are my typedefs:
Thanks for the code. I'll try to see what's happening, but it seems a bit strange. Which Interprocess version are you using? I'll recommend you to test your code agains latest cvs code. Apart from that, can you tell which system are you using, windows, or unix? And, can you which is the value of SEGMENT_SIZE, SEGMENT_NAME, MAP_NAME you are using (it shouldn't matter, but who knows...)?
The myMap pointer in the second process is not NULL, it has the same value as in the first process. Everything worked fine with boost.shmem. Anybody got a clue, what is wrong here and what is so different between how boost.shmem and boost.inteprocess perform these operations?
In theory, apart from some bug fixes, the mechanism is the same, but I might have introduced some bug. However, you say both base addresses are the same, so the bug does not seems to be related to using absolute addresses somewhere in the internal code by mistake.
Can boost.shmem and boost.interprocess coexist? If I'm stuck with boost.shmem for storing the map in shared memory, can I still use an upgradable mutex from boost.interprocess?
I haven't tested it but as long as you use only upgradable mutex from Interprocess, all should work. But don't try to mix managed shared memory from Interprocess with allocators from Shmem, for example, because it will crash.
Thanks, Szilard
Regards, Ion
participants (2)
-
Ion Gaztañaga
-
Pataki Szilard