Reputation: 419
I need to known if that the messages insinde an IPC queue is orderered. In practise I need to know if when a call a msgrvc function I get the first message enetered the queue or the selected message is random.
Now, I put this question because when inside a portion o code msgrcv get a message which is not intended for that code I usually requeue the message e read the following message in the queue. What I 'm wondering about is that given, for example, he following messages
msgA, msgB, msgC
, stored inside a queue If read the msgA and reque it I will get the queue with the messages in this new order
msgB , msgC, msgA
and so the following call to msgrcv will give me msgB or if that order is random ans so I can read again msgA
Thanks, Enzo
Upvotes: 0
Views: 687
Reputation: 21
The message queue in general works as first in first out buffer but there are ways of modifying that.
There is a good example of this in The Linux Programming Interface, see section 46.2.2.
The problem you will always have with returning the message to the same queue is sooner or later you are going to encounter it again, and if it wasn't suitable for the thread in question the first time around I am assuming it will also be unsuitable on the second and subsequent times around as well.
Have you considered using a token ring type approach, with several message queues set up? I.e. the first queue is received by your thread and if the message has been read but is not of interest it is then placed on a second queue for consumption by the next thread; this would then continue until a gradually reducing set of messages has been read by all the threads.
Upvotes: 2
Reputation: 7784
An IPC message queue is, as its name suggests, is a queue, so re-queuing would work.
I doubt it will be quicker than selecting the type though, msgrcv
just has to check the type of each message in the queue until it finds the first message with that type. Your code, removes the message, checks the type and queues it again.
Upvotes: 0
Reputation: 1
Seems like you want to select what to read from an IPC msg queue. Instead of re-queuing you could use the message type argument of msgrcv and msgsnd.
Upvotes: 0