Using notify as a semaphore and mailbox in parallel

Hi all,

I’m trying to understand how can I use notification.
I wonder if it’s possible to use task notifications as a semaphore and mailbox for the same task in parallel. (or semaphore and event group in parallel)

Thanks!

No, if you want to use something as both semaphores and mailboxes, it would need to be queues. Both semaphores and mailboxes are realized as instances of queues. One property of notifications is that they do NOT “carry a payload,” meaning something that both the task/ISR that post something and the task/ISR that unqueue can look at. You can roughly look at semaphores as mailboxes with an ignored content. Task notifications are signals.

I have a hard time seeing how and why you would ues something as both a semaphore and a mailbox, though. You can of course use a mailbox and not use the payload in some cases, but experience tells that this way you incur additional errors in your code.

Here is a good description FreeRTOS task notifications, fast Real Time Operating System (RTOS) event mechanism including their usage as (binary) semaphore etc.

If you mean a semaphore to tell you when the mailbox has been filled, yes.
Otherwise you would need to use the new feature of providing multiple notification words to each task.

Basically, a given notification word can act one of 3 ways:
As a counting semaphore.
As an event word with each bit having a meaning, or
As a fixed sized single item mailbox.

Great, thanks it was very helpful!

Uhm, isn’t that already implied in the mailbox semantics? Or do you mean filled with all possible entries?

Another interesting example of the combination of a ( counting ) semaphore and resources can be found here.

When a FreeRTOS+TCP application starts up, there are ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS buffers available. The buffers are stored in a List_t.
The semaphore does not hold any data, it only has a count. When xSemaphoreTake() succeeds, the count will decrement and a buffer can be taken.
When the buffer has been released, xSemaphoreGive() will be called to increment the count of free buffers.

Yes, but some people think of a mailbox as just a global variable and there needs to be something outside, like a semaphore, to indicate that new data is present. Just covering some possible interpretations of the request.

One property of notifications is that they do NOT “carry a payload,” meaning something that both the task/ISR that post something and the task/ISR that unqueue can look at. You can roughly look at semaphores as mailboxes with an ignored content. Task notifications are signals.

Hi ShowFoal,

this is an earlier quote of mine in this thread. May I ask for the motivation to repost it? Do you need to discuss aspects of it?

Welcome to the forum, by the way!