I'm using Boost 1.46 on Linux x86_64 in combination with gcc version 4.5.1. I'm trying to implement a a sparse matrix in a shared memory segment as a vector of maps. When trying to update previously inserted elements of the matrix, at a certain point, the program either crashes or stalls indefinitely. This only occurs if the gcc optimization is set higher than O0. If compiler optimizations are completely turned off (so using the -O0 switch) the program works as expected. Below, I provide some trimmed code that demonstrates the problem. I would be very grateful if somebody could indicate me what's causing this erratic behavior. Steven #include <iostream> #include <stdexcept> #include <boost/interprocess/managed_shared_memory.hpp> #include <boost/interprocess/containers/map.hpp> #include <boost/interprocess/containers/vector.hpp> #include <boost/interprocess/allocators/allocator.hpp> #define MATSIZE 5 typedef boost::interprocess::managed_shared_memory::segment_manager SegmentManager_t; typedef boost::interprocess::allocator<void , SegmentManager_t> VoidAllocator_t; typedef std::pair<int,double> MapValue_t; typedef boost::interprocess::allocator<MapValue_t , SegmentManager_t> MapValueAllocator_t; typedef boost::interprocess::map<int,double,std::less<int>,MapValueAllocator_t> Map_t; typedef boost::interprocess::allocator<Map_t,SegmentManager_t> MapAllocator_t; typedef boost::interprocess::vector<Map_t,MapAllocator_t> VectorofMaps_t; int main(int argc, char **argv) { VectorofMaps_t::size_type i; int j; Map_t::iterator mapiter; try { boost::interprocess::shared_memory_object::remove("MySharedMemory"); boost::interprocess::managed_shared_memory mfile(boost::interprocess::create_only,"MySharedMemory",65536); VoidAllocator_t alloc_inst (mfile.get_segment_manager()); VectorofMaps_t* pS=mfile.construct<VectorofMaps_t>(boost::interprocess::anonymous_instance)(MATSIZE,Map_t(std::less<int>(),alloc_inst),alloc_inst); for(i=0;i<MATSIZE;++i) { for(j=0;j<MATSIZE;++j) (*pS)[i].insert(std::pair<int,double>(j,1.0)); } for(i=0;i<MATSIZE;++i) { for(j=0;j<MATSIZE;++j) { mapiter=(*pS)[i].find(j); if(mapiter!=(*pS)[i].end()) mapiter->second+=1.0; else (*pS)[i].insert(std::pair<int,double>(j,1.0)); } } for(i=0;i<MATSIZE;++i) { for(mapiter=(*pS)[i].begin();mapiter!=(*pS)[i].end();++mapiter) std::cout<<mapiter->second<<" "; std::cout<<std::endl; } boost::interprocess::shared_memory_object::remove("MySharedMemory"); } catch(boost::interprocess::interprocess_exception e) { std::cerr<<"Interprocess error: "<<e.what(); } catch(std::exception e) { std::cerr<<"Standard exception: "<<e.what(); } catch(...) { std::cerr<<"unknown error"; } }