tags:

views:

22

answers:

2

If, under UNIX/Linux/BSD/OSX, I use this sequence of APIs in Application A:

    msgq_id = mq_open(  full_queue_name,
                        O_RDWR | O_CREAT,
                        S_IRWXU | S_IRWXG,
                        &msgq_attr);
    mq_send(msgq_id, ptrData1, len1, 0);
    mq_send(msgq_id, ptrData2, len2, 0);
    ...

and this sequence of events in Application B:

    mqd_t open_res = mq_open(full_queue_name, O_RDONLY);
    ...
    mq_receive(...)
    mq_receive(...)

... do I have a guarantee that the message queue maintains the order of the messages? That is, that Application B will receive the data from ptrData1 first, and then the data from ptrData2?

+1  A: 

From man mq_send on linux (emphasis added):

The msg_prio argument is a non-negative integer that specifies the priority of this message. Messages are placed on the queue in decreasing order of priority, with newer messages of the same priority being placed after older messages with the same priority.

So yes, you have a guarantee.

Williham Totland
+1  A: 

You get message that is oldest one of highest priority. So if you send all with same priority, you always receive them in same order.

vartec