Guarding MessageBuffer with a Mutex

jd-softcad wrote on Tuesday, May 22, 2018:

In one part of my project MessageBuffers are a great fit due to allowing variable size messages. The only problem is that there are multiple writers. While reading the documentation there are quite strong words regarding using multiple writers with MessageBuffers - that one needs to write in critical section and with a timeout of 0. This leads to me questioning the viablity of using a Mutex as a guard here.

Would it be safe to use MessageBuffers if access to them is guarded by a Mutex? The project uses preemptive scheduling.

rtel wrote on Tuesday, May 22, 2018:

Guarding a message buffer with a mutex can prevent more than one task
accessing at a time, but if one of the tasks accessing the message
buffer blocks on the message buffer then it will hold the mutex for the
entire block time.

jd-softcad wrote on Wednesday, May 23, 2018:

Thank you.

Coming from a Linux background the wording about critical section confounded me regarding vialibility of mutexes in the context of message buffers so I wanted to clarify.

May I suggest improving the wording of the stream/message buffer warning from:

(…) assumes there is only one task or interrupt that will write to the buffer (the writer), and only one task or interrupt that will read from the buffer (the reader).

to:

(…) assumes there is only one task or interrupt that will write to the buffer at a time(the writer) , and only one task or interrupt that will read from the buffer at a time(the reader).

Or something similar? Current wording suggests that unless a critical section is used it is illegal to have multiple writers regardless of other guards.