Ticket #4452: boost-interprocess-bug-report.cpp

File boost-interprocess-bug-report.cpp, 2.2 KB (added by Richard Murphy <richard.murphy@…>, 12 years ago)
Line 
1/*
2
3richardm@lukd02[dev-lon]$ g++ --version
4g++ (GCC) 4.3.2
5Copyright (C) 2008 Free Software Foundation, Inc.
6This is free software; see the source for copying conditions. There is NO
7warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8
9richardm@lukd02[dev-lon]$ uname -a
10Linux lukd02 2.6.18-92.el5xen #1 SMP Tue Apr 29 13:31:30 EDT 2008 x86_64 x86_64 x86_64 GNU/Linux
11
12THIS BUILD COMMAND WORKS OK
13 g++ boost-interprocess-bug-report.cpp -pthread -m64 -I/home/richardm/tools/boost/boost-1.43.0/include -O2 -L/home/richardm/tools/boost/boost-1.43.0/lib -Bstatic -lboost_thread -o d.out -Wl,-rpath /home/richardm/tools/boost/boost-1.43.0/lib
14
15THIS BUILD COMMAND BUILDS A EXE THAT SEGVS
16 g++ boost-interprocess-bug-report.cpp -DNDEBUG -pthread -m64 -I/home/richardm/tools/boost/boost-1.43.0/include -O2 -L/home/richardm/tools/boost/boost-1.43.0/lib -Bstatic -lboost_thread -o d.out -Wl,-rpath /home/richardm/tools/boost/boost-1.43.0/lib
17
18
19my boost install is a standard 1.43.0
20*/
21
22
23
24//////////////////////////////////////////////////////////////////////////////////////////////////
25#include <boost/interprocess/managed_mapped_file.hpp>
26#include <boost/interprocess/containers/vector.hpp>
27#include <boost/interprocess/allocators/allocator.hpp>
28
29#include <iostream>
30
31// using namespace boost::interprocess;
32
33
34typedef boost::interprocess::allocator<int, boost::interprocess::managed_mapped_file::segment_manager> MyAllocator;
35typedef boost::interprocess::vector<int, MyAllocator> MyVector;
36
37int main(int argc, char *argv[])
38{
39 try{
40 std::cout << "calling constructor.." << std::endl;
41 boost::interprocess::managed_mapped_file segment(boost::interprocess::open_or_create, "MyMemMapFile", 65536);
42 std::cout << "mapped." << std::endl;
43
44 MyAllocator alloc_inst (segment.get_segment_manager());
45
46 // the presence of this line causes the above managed_mapped_file constructor to segv
47 MyVector *myvector = segment.find_or_construct<MyVector>("MyVector")(alloc_inst);
48
49 std::cout << "vector constructed." << std::endl;
50
51 }
52 catch(std::exception & x )
53 {
54 std::cout << "exception:" << x.what() << std::endl;
55 }
56
57
58 return 0;
59};