Multiple Producers / single Consumer with Arduino


i am trying to program my arduino in order to have 2 producers and one consumer. But it blocks and i can not see anything on the serial monitor. this is the code i am trying :

When i add the consumer task the problem occurs.

Thanks in advance for your precious help

Your code seems ok so far.
Did you define configASSERT ?
Also printf-family functions often use quite a lot of stack. Maybe got an stack overflow.
Did you also define configCHECK_FOR_STACK_OVERFLOW ?
Or just try e.g. 1000 as stack size at least for the printing tasks.

Hello Giles,

There seems to be missing vTaskStartScheduler() function for launching the tasks

Thanks for your replies.
I am still new to the freertos so i have not played yet with the library and its configuration. I have included the <Arduino_FreeRTOS.h> and that s all. i also changed the stack size but still the same problem.

I believe in Arduino you do not need vTaskStartScheduler().

And as i said the problem only occurs when i add the cons task. without it the application run as it must be

Sorry, my mistake.
Arduino indeed does not need calling vTaskStartScheduler function.

Without the last element of your semaphore chain Prod_1 and Prod_2 run only once, isn’t it ?

Yes that s the case. But when i add it it does not work at all

BTW the 2 intial xSemaphoreTake are not correct.

The semaphore is created in the ’empty’ state, meaning the semaphore must first be given using the xSemaphoreGive() API function before it can subsequently be taken (obtained) using the xSemaphoreTake() function.

You should also check the return codes to be sure that all the semaphores and tasks etc. are successfully created.

Exactly that s what i have done and it shows fact in the beginning of each task i added a print and i’ve seen that it does not do any task. it creates the semaphore and gives it as i asked for but does not go to the tasks. That’s the weird thing i can not really find what is the problem

About the 2 intital Take : I believe the vSemaphoreCreateBinary creates a semaphore with count 1 so i have to take it to give it later ?

Hi, first time using this forum.
I had similar problem but i solved it by lowering memory to allocate for task aka the usStackDepth argument in xTaskCreate. I also recommend check potential failure to create a task or allocation of memory.