Boost logo

Boost Users :

Subject: [Boost-users] boost::interprocess on FreeBSD 7
From: Andy Wiese (andyw_at_[hidden])
Date: 2008-12-16 19:38:33


Using boost::interprocess from boost_1_37_0 on FreeBSD 7.0,

I get a segmentation fault in pthread_mutex_lock() from /lib/libthr.so.
3, in what appears to anything related to a ShmemAllocator.

For example, when I run the example from http://www.boost.org/doc/libs/1_37_0/doc/html/interprocess/allocators_containers.html#interprocess.allocators_containers.containers_explained

I get the segfault at this line:

//Initialize the STL-like allocator
const ShmemAllocator alloc_inst (segment.get_segment_manager());

I stepped back to this simple test after encountering this segfault
(always in pthread_mutex_lock) when trying to use almost any function
of segment_manager from managed_mapped_file. This is from an mapped
file boost::interprocess::map structure that works very well on darwin.

Is there any hope to getting this to work on FreeBSD?

-----------------------------------------------------------------------------------------------
FWIW, here is the complete text of the example:

void test_ipc2()
{
        using namespace boost::interprocess;
        shared_memory_object::remove("MySharedMemory");
        try{
                //A managed shared memory where we can construct objects
                //associated with a c-string
                managed_shared_memory segment(create_only,
                                                                          "MySharedMemory", //segment name
                                                                          65536);
                
                //Alias an STL-like allocator of ints that allocates ints from the
segment
                typedef allocator<int, managed_shared_memory::segment_manager>
                ShmemAllocator;
                
                //Alias a vector that uses the previous STL-like allocator
                typedef vector<int, ShmemAllocator> MyVector;
                
                int initVal[] = {0, 1, 2, 3, 4, 5, 6 };
                const int *begVal = initVal;
                const int *endVal = initVal + sizeof(initVal)/sizeof(initVal[0]);
                
                //Initialize the STL-like allocator
                const ShmemAllocator alloc_inst (segment.get_segment_manager());
                
                //Construct the vector in the shared memory segment with the STL-
like allocator
                //from a range of iterators
                MyVector *myvector =
                segment.construct<MyVector>
                ("MyVector")/*object name*/
                (begVal /*first ctor parameter*/,
                 endVal /*second ctor parameter*/,
                 alloc_inst /*third ctor parameter*/);
                
                BOOST_CHECK(myvector);
                //Use vector as your want
                std::sort(myvector->rbegin(), myvector->rend());
                // . . .
                //When done, destroy and delete vector from the segment
                segment.destroy<MyVector>("MyVector");
        }
        catch(...){
                shared_memory_object::remove("MySharedMemory");
                throw;
        }
        shared_memory_object::remove("MySharedMemory");
}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net