Implementation of printf that works in threads.

rtel wrote on Thursday, October 17, 2019:

Whenever you access any IO port, be that a console or a UART or anything else, you are going to have to serialise the access. There are a few ways you can do that, for example use a mutex, but the mutex would have to be around the entire string write not just the individual characters. Another method would be to use something like a stream buffer - anything that wants to write to the output writes the message to the stream buffer, and then you have a task that drains the stream buffer and writes anything it obtains from the buffer to the output. Note stream buffers only expect one writer though, so then the mutex has to be around the stream buffer (so maybe that doesn’t gain anything?).