Free RTOS Task Notifications

Hello,

This is my first time using Task notifications and I’m having some trouble getting it to work. Below is what I have set up.

Three tasks:
Task 1, Task 2, and Task 3.

All three tasks are created at the same time.
Task 2 & 3 have osPriorityNormal and Task 1 osPriorityRealtime (from cmsis).

Task 1 finishes processing some data and then notifies the other two tasks like so:

xTaskNotify(Task_2_handle, 0, eNoAction);
xTaskNotify(Task_3_handle, 0, eNoAction);

Task 2 and 3 both have this at the start of their threads (before entering their respective infinite loops):

xTaskNotifyWait(0, 0, NULL, portMAX_DELAY);

Task 2 and 3 never receive the notification. Any idea why?

Maybe there’s a better way to prevent execution of Task 2 and 3 until Task 1 is finished with its initial processing? I’ve tried just starting Task 2 and 3 suspended and resuming them in task 1 sequentially; but that didn’t work either.

Thank you

Better (read: never ever) use suspend/resume for task synchronization.
Task notifications are fine and are designed for purposes or use cases like yours and you’ve chosen a good approach.
Also your code looks ok.
Are the task handles valid ? Could you show the task creation and the task function code, too ?

1 Like

Better (read: never ever) use suspend/resume for task synchronization.

Noted, thank you.

Task 1:

osThreadId task1_id;
osThreadDef(task1, task1_thread, osPriorityRealtime, 0, 256);
task1_id = osThreadCreate(osThread(task1), NULL);

Task 2:

osThreadId task2_id;
osThreadDef(task2, task2_thread, osPriorityNormal, 0, 896 );
task2_id = osThreadCreate(osThread(task2), NULL);

Task 3:

osThreadId task3_id;
osThreadDef(task3, task3_thread, osPriorityNormal, 0, 384);
task2_id = osThreadCreate(osThread(task3), NULL);

I should mention all three tasks are/have been working fine. I just discovered a race condition with the execution of the three and decided to do this to rectify that.

I actually just noticed that this triggers the following assert in tasks.c:

configASSERT( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) == NULL );

Looks like it occurs when notifying Task 3.

I think the assert comes from a memory corruption of FreeRTOS internal data.
Very often memory corruptions are caused by stack overflows.
Did you enable stack checking for development ?
Or just retry your application with increased stack sizes.
For instance using printf family functions required relatively large stacks.

1 Like

Turns out I was notifying Task 3 before it had even been created. There was a separate thread in the system that creates and initializes Task 3. Problem solved.

Thanks for your help