System V——后进先出方式

System V - LIFO way

我正在使用 System V 来管理消息队列。 我成功地制作了一个工作原型,一切都按预期工作,但是我想要一个 LIFO 队列而不是 FIFO(预计最后发送的 msgsnd 消息首先读取 msgget)。

这可能吗?

是的,如果您正确管理消息类型。 msgrcv 手册指定:

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.

然后,如果您发送 msgtyp 严格递减的消息,msgtyp 等于 LONG_MIN 的提取将始终为您提供最后发送的消息。 msgtyp 在这种情况下扮演优先级的角色,1 是最大的。

我觉得不可能。

术语“队列”表示 FIFO。参见维基百科:

Queue (abstract data type)

In computer science, a queue (/ˈkjuː/ KYEW) is a particular kind of abstract data type or collection in which the entities in the collection are kept in order and the principal (or only) operations on the collection are the addition of entities to the rear terminal position, known as enqueue, and removal of entities from the front terminal position, known as dequeue. This makes the queue a First-In-First-Out (FIFO) data structure.