I'm using System V to manage a message queue.
I successfully made a working prototype, everything works as expected, however I would like to have a LIFO queue instead of FIFO (expected last msgsnd
message sent is first read msgget
).
Is this possible ?
Yes if you manage correctly message types. msgrcv
manual specifies:
The argument msgtyp specifies the type of message requested as follows:
If msgtyp is 0, the first message on the queue is received.
If msgtyp is greater than 0, the first message of type msgtyp is received.
If msgtyp is less than 0, the first message of the lowest type that is less than or equal to the absolute value of msgtyp is received.
Then if you send messages with strictly decreasing msgtyp
, an extraction with msgtyp
equals to LONG_MIN
will always give you the last sent message. msgtyp
plays the role of a priority in this case, 1 being the greatest.