Mario Charest
|
Re: QNX Messages threadsafe?
|
Mario Charest
03/28/2008 11:49 AM
post6252
|
Re: QNX Messages threadsafe?
> I have a MessageHandler() function for a process to handle incoming QNX
> messages, that will immediately respond to any messages sent with a MsgReply()
> , then actually pull the data out and process the message. I'm using this to
> make a QNX message similar to an asynchronous pulse, but able to send an
> arbitrary amount of data. I understand that message data is copied between
> process address spaces, and the message itself should hang around for the
> scope of the MessageHandler() function. If I then received another message
> before I finished processing the first one could I run into problems with the
> second message getting copied over the memory of the first one?
>
> Here's an example:
>
> void MessageHandler(void *Msg, int Type, int ReceiveID)
> {
> MsgReply(ReceiveID, EOK, NULL, 0); // reply immediately
>
> MyMsgType *foo = (MyMsgType*)Msg;
>
> int a = foo->GetAValue();
>
> // if I do more stuff here, foo pointer should still be valid for the
> // scope of this function, but if I immediately get another message
> // will Msg (and foo) get overwritten?
Not until you a the MsgReceive. If that is a problem in your design, just pass MsgReceive a different pointer, a
circular queue type of design.
By the way have you looked at the async_ stuff which are ok as long as you don't need networking.
> }
|
|
|