Boost logo

Boost Users :

Subject: [Boost-users] Crash in managed_shared_memory
From: Abhishek Kumar Pandey (akpandey_at_[hidden])
Date: 2015-09-28 00:40:33


Hi,

I am using managed_shared_memory in my program. The program runs fine if only one instance is used. However if more than one instance is used then one instance dies randomly.
The instance dies at the following code :

char_string key_object(keyHashStr.c_str(), alloc_inst3);

The sample program is :

-----------------------
#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
#include <boost/interprocess/containers/string.hpp>
#include <string>
#include <iostream>

#define RESERVED_BUFFER_SIZE_WRITE (8 * 0x0100000)

namespace bip = boost::interprocess;

//Typedefs of allocators and containers
typedef bip::allocator<char, bip::managed_shared_memory::segment_manager> char_allocator;
typedef bip::basic_string<char, std::char_traits<char>, char_allocator> char_string;

int main()
{
       bip::managed_shared_memory m_sharedMemUsage(bip::open_or_create, "MyBookkeeper", 2 * RESERVED_BUFFER_SIZE_WRITE);

       char_allocator alloc_inst3(m_sharedMemUsage.get_segment_manager());
       for (int count = 0; count < 100000; ++count) {
              char_string key_obect("AAAAAAAAAAAAAAAAAAAAAAA", alloc_inst3);
       }
}
-----------------------

Please let me know if I am missing something in this program.

Regards,
Abhishek



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