Serial write from multiple threads

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
jackt
Posts: 1
Joined: Mon Apr 07, 2014 4:14 pm

Serial write from multiple threads

Post by jackt »

Hi,

I would like to make multiple write calls to the serial port from different threads. I want to make sure that all of the calls in a given portion of a thread are performed sequentially and not interrupted by another thread. What is the best mechanism to do this?

My hunch is that this is a fairly straightforward issue that shows my ignorance of general RTOS principals. Can anybody recommend a resource to learn general best practices when dealing with RTOS threads and interrupts?

Thanks!
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Serial write from multiple threads

Post by Giovanni »

Hi,

This is a common problem, you need to do mutual exclusion using a mutex or a semaphore. The threads would take the mutex/semaphore, perform their I/O and finally release the mutex/semaphore. The I/O operation will be atomically performed.

I think this can help: http://www.chibios.org/dokuwiki/doku.ph ... sion_guide

Giovanni
Post Reply