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.

Wait until a Mailbox message has been processed

I have a multi-tasking application running on an MSP430 with TI-RTOS. In my setup there is a main event handler, which pends on a message to process, and other tasks can post messages for it to process. The message queue is a Mailbox.

I'm looking for a way to make a posting task block until its message has been serviced (not only dequeued, but processed). Right now I'm thinking of adding a semaphore handle to each message on which the posting task wants to wait.

Is there a better way of achieving this?

P.S. I would have settled for the Mailbox's 'writerEvent', but the manual says only one task can pend on such an event, and I have a multi-tasking scheme.

  • Hi Boaz,

    That seems like a reasonable solution.  You could have the Semaphore be a local variable on the task's stack to avoid the memory allocation.  For example, something like this in the task sending the message:

        MsgObj      msg;
        Semaphore_Struct sem;
        Semaphore_Params semParams;

        Semaphore_Params_init(&semParams);
        semParams.mode = Semaphore_Mode_BINARY;
        Semaphore_construct(&sem, 0, &semParams);

        msg.sem = Semaphore_handle(&sem);

        Mailbox_post(mbx, &msg, BIOS_WAIT_FOREVER);
        Semaphore_pend(Semaphore_handle(&sem), BIOS_WAIT_FOREVER);

    You could create the Mailbox with one message since your tasks must wait for the message to be processed anyway:

        mbx = Mailbox_create(sizeof(MsgObj), 1, &mbxParams, NULL);

    Your task for processing the message would post the semaphore:

            Mailbox_pend(mbx, &msg, BIOS_WAIT_FOREVER);
            ...
            Semaphore_post(msg.sem);

    Best regards,

        Janet