Boost logo

Boost :

Subject: [boost] Boost interprocess: Segmentation fault
From: thuannv (thuannv.it.technical_at_[hidden])
Date: 2011-11-08 05:57:37


Hi everybody,
I am beginner to develop with boost library. I am working with shared memory
(boost.interprocess). So, I got error in executing and could anyone help me
solve this problem?
My problem is:
- I wrote 2 process named SHMWriter and SHMReader.
    + SHMWwriter: write a map (int, int) into the SHM.
    + SHMReader: read the map value from SHM.
- I executed the SHMWriter then SHMReader.
- SHMWriter successfully executed. But, SHMWriter always executed failed
(error: Segmentation fault).
- The sources code are listed below:

//SHMWriter:
--------------------------------------------
typedef std::pair<int, int> MapValue;
typedef allocator<MapValue, managed_shared_memory::segment_manager>
MapAllocator;
typedef map<int, int, std::less&amp;lt;int>, MapAllocator> IntegerMap;

const char* segName = "MAPSEGMENT";
const char* mapName = "MAPNAME";

int main() {
   shared_memory_object::remove(segName);
   managed_shared_memory segment(create_only, segName, 1000);

   MapAllocator allocator(segment.get_segment_manager());

   IntegerMap* pOffsetMap =
segment.construct<IntegerMap>(mapName)(std::less<int>(),

allocator );

   int key = 1;
   int ivalue = 10;

   MapValue value(key, ivalue);

   pOffsetMap->insert(value);
   return 0;
}

//SHMReader
-----------------------------
typedef std::pair<int, int> MapValue;
typedef allocator<MapValue, managed_shared_memory::segment_manager>
MapAllocator;
typedef map<int, int, std::less&amp;lt;int>, MapAllocator> IntegerMap;

const char* segName = "MAPSEGMENT";
const char* mapName = "MAPNAME";

int main() {

   try {
       managed_shared_memory segment(open_only, "MAPSEGMENT");
       IntegerMap* pMap = segment.find_no_lock<IntegerMap>(mapName).first;
       int key = 1;
       int value = pMap->at(key);
       std::cout << value << std::endl;
   }
   catch(interprocess_exception& ie) {
       std::cout << ie.what() << std::endl;
   }
   catch(std::exception& stde) {
       std::cout << stde.what() << std::endl;
   }
   return 0;
}

--
View this message in context: http://boost.2283326.n4.nabble.com/Boost-interprocess-Segmentation-fault-tp4015593p4015593.html
Sent from the Boost - Dev mailing list archive at Nabble.com.

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk