This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Mailbox vs Queue+Event

Other Parts Discussed in Thread: ENERGIA

I want to decide whether to use a Mailbox or a Queue+Event.  In my application, multiple writer tasks send single 32-bit message pointers to a single reader task.  I want to use a Mailbox because an event can be automatically posted to the reader task.  With a Queue, a separate operation is required to post an event.  

"SYS/BIOS (TI-RTOS Kernel) v6.40 User Guide", section 4.5.4 "Atomic Queue Operations" describes a separate API which disables interrupts for Queue operations when a Queue is shared by multiple tasks.  There is no corresponding section in the User Guide for Mailboxes.  

Why is disabling interrupts necessary for Queues and not Mailboxes when the data structure is shared by multiple tasks?

  • Henlee,

         A mailbox is a synchronization object in itself while a queue is not. Tasks can pend/block on a mailbox or post to it thereby access to a mailbox can be synchronized/protected. A queue is just a list of objects, inserting and removing from the queue is non-blocking and is not protected. The atomic operations you read about is there to protect access to the queue. With a mailbox you can use the pend and post in your design to protect accesses from multiple tasks.

    Moses

  • Henlee,

    Here are a couple more items to think about.

    1. The mailbox implementation is copy-based. The queue implementation is not.

    2. With mailbox, you must pre-allocate the internal messages. If the mailbox becomes full, then the writing task will block (yield) until a message is available. A queue can always accept a new message.

    3. A queue message requires an embedded Queue_Elem. The mailbox does not.

    4. With a queue, you must manage the buffer pool yourself.

    ~Ramsey

  • These are both helpful answers.  I will use Mailboxes.  Found a simple example here:

    http://e2e.ti.com/support/embedded/tirtos/f/355/t/258201.aspx

  • Thank you for the hint. I decided to implement the mailbox only —and not the queue— for Energia.