In this post, I will discuss the differences between message queues, mailboxes, and pipes. Message queues, mailboxes, and pipes are services that are provided by RTOSs that enable tasks to communicate with each other. Tasks need to communicate with each other in order to coordinate activities and to share data.
If you need strong control over prioritization, mailboxes might be a good choice. You can easily prioritize mailbox messages no matter when they entered the mailbox.
This characteristic provides a definite advantage over other inter-task communication options such as queues which are particularly sensitive to the order in which messages are added and removed from the data structure.
The other benefit of mailboxes is that there is typically no size limit on individual mailboxes. The size limit is typically fixed and is set by the programmer.
If you have an implementation that requires first-in-first-out prioritization, queues are a great choice. They are flexible and relatively easy to implement, making them a common choice in RTOS implementations.
The downside of queues is that, unlike mailboxes, you are often limited in the amount of data that you can write to the queue in any given call. Many RTOSs don’t have a lot of flexibility when it comes to this.
If you need to be able to write messages of varying lengths, pipes are the best choice. Pipes are identical to queues except they are byte-oriented. The main difference between pipes and queues is that pipes allow you to write messages of any length, while queues do not.