Reputation: 1798
In operating system what is the difference between message queues and mailboxes.
Upvotes: 6
Views: 11080
Reputation: 93486
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.
Upvotes: 6
Reputation: 35
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.
Upvotes: 0
Reputation: 7057
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:
Upvotes: 12