This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Is UART_write() thread safe in blocking mode ?

Hi, 

Is UART_write() in blocking mode (as well as other prolonged driver functions) thread safe ?

e.g. - consider the following scenario:

- Low priority thread A is blocked on long UART_write() operation...

- Now high priority Thread B preempts thread A and tries to UART_write() as well.

What happens in this situation? Will Thread A's UART_write() conclude gracefully ?  Do UART_write() calls use some locking mechanism ?

Thanks

  • UART_write() does not really have a lock, but we check if the UART object has data left to write before returning an error. When the UART is in blocking mode, we do pend on a Semaphore until the hardware is finished, so Thread A will be blocked. So, if Thread B attempts a UART_write() before the Thread A's request has finished processing, it would just fail, and the Thread A's request will continue to be processed until it's finished. This is assuming that they are using the same UART module.

    Gilbert