문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top