Boost logo

Boost Users :

Subject: [Boost-users] [interprocess] access dynamically accessed shared region in another process
From: Stephan Menzel (stephan.menzel_at_[hidden])
Date: 2009-04-01 11:51:03


Hi there,

I'm trying to do IPC via boost.interprocess and use a dynamic buffer. This is on windows, debug mt, boost 1.38.

To do this, I first create a shared segment and then a dynamic area in it. like this:

struct transfer_buffer {
void *buf;
size_t bufsize;
boost::interprocess::interprocess_mutex mutex;
size_t dmember;
}

typedef boost::interprocess::managed_windows_shared_memory shared_segment;
...
using namespace boost::interprocess;
shared_memory_object::remove(bufname);

struct transfer_buffer *ret = 0;

shared_segment_ptr seg;// I use a ptr to store the object away so it won't get lost
seg.reset(new shared_segment(create_only, bufname, begin_size));

// and our maintanance struct in it
ret = seg->construct<struct transfer_buffer>(unique_instance)();
ret->dmember = 42;
const std::size_t Alignment = 128;
ret->bufsize = 1982781;
ret->buf = seg->allocate_aligned(ret->bufsize, Alignment);

Then, process A writes into the dynamic buffer, which seems to work OK.
In the other process however, I try to open it and read the data. Like this:

seg.reset(new shared_segment(open_only, bufname));
ret = seg->find<struct transfer_buffer>(unique_instance).first;

Now I can access everything fine in ret (the struct itself), including the mutex and data members. But I cannot access the dynamically allocated buffer. As soon as I access it (read it, memcpy, anything) the app crashes with what would appear to be a rather broken callstack.
When I look at the transfer_buffer struct before the crash it looks as if the dynamic pointer points to some inaccessable area. Not what I wrote in it anyway.

Do I have to do anything else (other than creating the segment and find() the unique transfer_buffer struct) in the other process to access the dynamic area? Or is this a bug?

Any help appreciated...

Stephan


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