Mutex or Queue?

which way to access data from multiple tasks is better?

Multiple tasks continuously set data to be sent, and one sends all the data at regular intervals.

  1. global variable accessible via mutex
  2. queue

I tried both options, but I don’t know which one is better (safer, faster).

try a reader writer lock. Query the forum for that term if you are not familiar with the concept.

Personally, if the Queue fits the accessing, then it is probably good enough and avoids you having to effectively recreate its code with a mutex.

If the way the data is accessed doesn’t match how a Queue works, like you aren’t sending out in the order that the data is collected, then use the Mutex.

1 Like

Both options mentioned will work but I’m overall with @richard-damon on this one. No point avoiding the already-provided functionality of the FreeRTOS Queue.