Stream Buffer vs. Message Buffer

The documentation says that you must not let two sources try to write to the Buffer at the same time or two sinks read at the same time. If all the Sources or Sinks are tasks, then a Mutex could be used to protect the Buffer, and that would make sure that you never get the prohibited simultaneous access. If an ISR might be a possible source/sink, a Mutex won’t work, then you need the critical section method.

The source side and the sink side are independent for this, and each can use which ever method works for it (if needed).

Note, using a Mutex for protection can cause a form of Priority Error, as a Higher priority task that reaches the mutex after a Lower Priority task already has it is stuck in line behind it, and doesn’t use it priority, unlike how a Queue would work, which gives the Queue to the highest priority task waiting. This is precisesly the sort of case described in the Documentation that buffers do not support.

The one advantage of the “Critical Section” method is it sort of gets around this, because once in the critical section, a Higher Priority task can’t try to get to the Buffer, due to the critical section, but comes at the cost that you don’t block if the action can’t proceed, so you need to do something else to wait.

1 Like