Difference between message queues and mailboxes
Asked Answered
C

3

6

In operating system what is the difference between message queues and mailboxes.

Cordiality answered 27/10, 2015 at 15:24 Comment(1)
It entirely depends on the system and how it uses the terminology.Baudelaire
R
12

I suspect there is no universally accepted definition for what makes a message queue versus a mailbox. Each RTOS may use different terminology and implementation details so you'd have to look at each RTOS individually.

Generally speaking some of the common differences include:

  • Is the size of the messages sent through the queue/mailbox fixed or can the message size vary?
  • Does the queue/mailbox hold a reference to the message or a copy of the message?
  • Can the queue/mailbox hold one message, multiple messages, or unlimited messages?
Rarotonga answered 27/10, 2015 at 16:11 Comment(0)
S
6

A queue in general has very precise meaning in computing as a container data structure with first-in-first-out (FIFO) access semantics. In an RTOS queue specifically, access to the queue will be thread-safe and have blocking semantics.

A mailbox on the other hand has no generally accepted specific semantics, and I have seen the term used to refer to very different RTOS IPC mechanisms. In some cases they are in fact queues, but if the RTOS also supports an IPC queue, a mailbox will have somehow different semantics - often with respect to memory management. In other cases a mailbox may essentially be a queue of length 1 - i.e. it has the blocking and IPC capability of a queue, but with no buffering. Such a mechanism allows synchronous communication between processes.

Sussex answered 1/11, 2015 at 14:51 Comment(0)
S
0

Mailboxes are implemented using Queue and Semaphore. If multiple threads are blocked to push data on to the full Queue using the mailbox put() method, upon availability of space only one thread can see the space available and allowed to push data onto the Queue with atomic cycle. Without atomic guarantee, another thread can push data to the Queue in the time another thread checked the size and push the data. Similarly if more then 1 thread is waiting to get the data to empty Queue , it can also be implemented in atomic way.

But mailboxes have extra overhead as compare to Queue.

Sphacelus answered 10/3, 2021 at 19:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.