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
#include
#include
#include
#define MATSIZE 5
typedef boost::interprocess::managed_shared_memory::segment_manager
SegmentManager_t;
typedef boost::interprocess::allocator
VoidAllocator_t;
typedef std::pair MapValue_t;
typedef boost::interprocess::allocator
MapValueAllocator_t;
typedef
boost::interprocess::map
Map_t;
typedef boost::interprocess::allocator
MapAllocator_t;
typedef boost::interprocess::vector 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(boost::interprocess::anonymous_instance)(MATSIZE,Map_t(std::less<int>(),alloc_inst),alloc_inst);
for(i=0;i(j,1.0));
}
for(i=0;isecond+=1.0;
else
(*pS)[i].insert(std::pair(j,1.0));
}
}
for(i=0;i