Hello FreeRTOS Community,
I recently started using FreeRTOS with STM32L471 Cortex M4 MCU. I’m having fun and I really like it. The documentation and manuals are well written – clear and easy to understand! I would like to ask for a clarification, though, regarding the scenario of multiple tasks sending items to a queue. To be clear I give some details below.
I have a low-priority “diagnostic task” responsible for receiving messages from a “dignostic queue” and sending them via UART DMA. The messages contain pointers to strings in predefined buffers. That is, strings are not sent in the queue – just pointers to the strings.
Several other tasks (of higher and possibly equal priority) send messages to the “diagnostic queue” asynchronously. I use a mutex to ensure only one task is writing a string to a predefined buffer at a time. Once a pointer to the string is obtained I release the mutex and call xQueueSendToBack() to send the pointer to the “diagnostic queue”.
This appers to work well and I’ve not encountered any problems. My question is whether releasing the mutux before calling xQueueSendToBack() is safe, or that I should only do so after xQueueSendToBack() returns. Could someone clarify?
I’ve not seen any examples whereby several tasks sending messages to the same queue require a mutex obtain/release around xQueueSendToBack(). So, I think I’m okay. I just wanted to check with the experts.
Presumably there is already a mechanism that prevents more than one task from writing into the same queue at the same time?
Thanks for any clarification!