[Boost-users] global instances for managed_shared_memory & message_queue

53 views
Skip to first unread message

bb.andersen

unread,
Jun 24, 2013, 6:45:40 PM6/24/13
to boost...@lists.boost.org
Dear Boost Grurus,

First of all let me thank you for the huge effort that people like Mr.
Gaztañaga has made to keep boost interprocess improved. It is a really
time-saver API!

I have a very basic question that, despite the large amount of documentation
I've looked, I haven't clarified yet.

I just want to create a global static variables (i.e. instances) for
managed_shared_memory, message_queue, mutex and condition var.

By now I have my app prototype (CGI) is running fine with auto vars, as
appeared in the several examples:

/main() {
...
boost::interprocess::permissions perm;
perm.set_unrestricted();
managed_shared_memory segment(create_only,"MonitorOEE_SharedMemory", 65536,
0, perm);
...
message_queue mq(create_only, "MonitorOEE_MessageQueue", 256,
sizeof(t_QRequest), perm);
...
named_mutex mutex_waiting(create_only, namedMutex, perm);
...
named_condition cdv_wakeup(create_only, namedConditionVar, perm);
...
}/

All segment, mq, cdv_wakeup live in the context of the main function...

Now I want them to be globally accessible from different functions. But I am
not able to. I just partially succeeded creating global pointers to
managed_shared_memory and message_queue. But when constructing object to the
pointer segmentation faults appear...

///Global Declarations
...
static boost::interprocess::message_queue *mq;
static boost::interprocess::managed_shared_memory *segment;
static boost::interprocess::interprocess_mutex mutex_waiting;
static boost::interprocess::interprocess_condition cdv_wakeup;
...

main() {
..
std::auto_ptr<boost::interprocess::managed_shared_memory>ptr01(new
boost::interprocess::managed_shared_memory(open_only,"MonitorOEE_SharedMemory"));
segment = ptr01.get();
//this seems to work but fails when constructing objects:
IPC_SOAPRequest *pSOAPRequest
=segment->construct<IPC_SOAPRequest>(namedSOAPRequest)();
(the autovar counterpart works seamlessly)
...
std::auto_ptr<boost::interprocess::message_queue>ptr02(new
boost::interprocess::message_queue(open_only,MonitorOEE_MessageQueue"));
mq = ptr02.get();
//Seems to work...(send and receive)
..
//dunno how to instantiate to mutex and cond var global references
}
/
I am sure it should be an easier and tidier way. Can you give me just the
first steps to work this out? I've been sleepless a couple of nights.

Eskerrik Asko! (Thanks in the basque language!)

--
View this message in context: http://boost.2283326.n4.nabble.com/global-instances-for-managed-shared-memory-message-queue-tp4648903.html
Sent from the Boost - Users mailing list archive at Nabble.com.
_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Ion Gaztañaga

unread,
Jun 27, 2013, 6:16:11 PM6/27/13
to boost...@lists.boost.org
El 25/06/2013 0:45, bb.andersen escribió:
> Dear Boost Grurus,

> I just want to create a global static variables (i.e. instances) for
> managed_shared_memory, message_queue, mutex and condition var.

I haven't tried that do that. Maybe some OS functions are not prepared
to be called before main, or there is some bug preventing this use.
Could you provide a full compilable example so I can investigate it more
easily?

thanks,

ion

Reply all
Reply to author
Forward
0 new messages