Boost logo

Boost Users :

Subject: Re: [Boost-users] boost managed shared memory: RUN FAILED
From: Olivier Austina (olivier.austina_at_[hidden])
Date: 2012-12-03 10:28:32


Hello,

I send to you the program. I take it from an example on the boost site :

#include <boost/interprocess/managed_
shared_memory.hpp>
#include <boost/interprocess/containers/vector.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
#include <string>
#include <cstdlib> //std::system

using namespace boost::interprocess;

//Define an STL compatible allocator of ints that allocates from the
managed_shared_memory.
//This allocator will allow placing containers in the segment
typedef allocator<int, managed_shared_memory::segment_manager>
ShmemAllocator;

//Alias a vector that uses the previous STL-like allocator so that allocates
//its values from the segment
typedef vector<int, ShmemAllocator> MyVector;

//Main function. For parent process argc == 1, for child process argc == 2
int main(int argc, char *argv[])
{
   if(argc == 1){ //Parent process
      //Remove shared memory on construction and destruction
      struct shm_remove
      {
         shm_remove() { shared_memory_object::remove("MySharedMemory"); }
         ~shm_remove(){ shared_memory_object::remove("MySharedMemory"); }
      } remover;

      //Create a new segment with given name and size
      managed_shared_memory segment(create_only, "MySharedMemory", 65536);

      //Initialize shared memory STL-compatible allocator
      const ShmemAllocator alloc_inst (segment.get_segment_manager());

      //Construct a vector named "MyVector" in shared memory with argument
alloc_inst
      *MyVector *myvector =
segment.construct<MyVector>("MyVector")(alloc_inst);*
 * ;*

   }
   else{
       // some code here
   }

   return 0;
};

The program can not run this instruction: *MyVector *myvector =
segment.construct<MyVector>("MyVector")(alloc_inst);

*I am using Netbeans 7.1.2 with cygwin 4.x on windows XP SP3 and boost
1.48.

When I run it in external terminal I got this error:
*/cygdrive/C/Program Files/NetBeans 7.1.2/ide/bin/nativeexecution/dorun.sh:
line
33: 12900 Segmentation fault (core dumped) sh "${SHFILE}"

*When I debug it I got this :
Signal received SIGSEGV(segmentation fault)

Thank you and any suggestion is welcome.*
*Austina*

*
2012/12/3 Joshua Boyce <raptorfactor_at_[hidden]>

> On Fri, Nov 30, 2012 at 10:00 PM, Olivier Austina <
> olivier.austina_at_[hidden]> wrote:
>
>> Hello,
>>
>> This is the details of the error I got (with Netbeans) :
>>
>> 12 [main] cppapplication_4 3608 exception::handle: Exception:
>> STATUS_ACCESS_VIOLATION
>> 371 [main] cppapplication_4 3608 open_stackdumpfile: Dumping stack
>> trace to cppapplication_4.exe.stackdump
>>
>>
>> RUN FAILED (exit value 35 584, total time: 2s)
>>
>> Many thanks
>>
>>
>> 2012/11/30 Olivier Austina <olivier.austina_at_[hidden]>
>>
>>> Hello,
>>>
>>> I try to run an example from this online book(
>>> http://en.highscore.de/cpp/boost/interprocesscommunication.html) and I
>>> got "RUN FAILED (exit value 1, total time: 938ms) ". I am using Netbeans.
>>> This is the example:
>>>
>>>
>>> #include <boost/interprocess/managed_shared_memory.hpp>
>>> #include <iostream>
>>>
>>> int main()
>>> {
>>> boost::interprocess::shared_memory_object::remove("Highscore");
>>> boost::interprocess::managed_shared_memory managed_shm(boost::interprocess::open_or_create, "Highscore", 1024);
>>> int *i = managed_shm.construct<int>("Integer")(99);
>>> std::cout << *i << std::endl;
>>> std::pair<int*, std::size_t> p = managed_shm.find<int>("Integer");
>>> if (p.first)
>>> std::cout << *p.first << std::endl;
>>> }
>>>
>>>
>>> Thanks very much.
>>> --
>>> Regards
>>> Austina
>>>
>>>
>>>
>>
>>
>> --
>> Regards
>> Austina
>>
>>
>>
>> _______________________________________________
>> Boost-users mailing list
>> Boost-users_at_[hidden]
>> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
>
> You may have more luck getting an answer if you post the generated stack
> dump (cppapplication_4.exe.stackdump).
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>

-- 
Regards
Austina


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