enzo1959
enzo1959

Reputation: 419

How are ordered the messages insinde an IPC queue

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

Answers (3)

Kev Scott
Kev Scott

Reputation: 21

The message queue in general works as first in first out buffer but there are ways of modifying that.

  • If you call msgrcv() with the msgtyp set to zero you will get the first message in the queue.
  • If you call it with the msgtyp set to > 0 the queue will only return messages with types corresponding to the number specified by msgtyp and this subset will still be delivered in a first in first out fashion.
  • If you call it with the msgtyp set to < 0 the first message with the type set equal to or less that the absolute value of msgtyp will be returned but yet again it is first in first out.

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

parkydr
parkydr

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

Meallia
Meallia

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

Related Questions