ThreadX contains contains message queues that allow inter-thread communication. Suppose I have several threads that read and write to a queue. Do I have to synchronize access to this queue (e.g. using a mutex)?
access a threadx-queue concurrently
764 Views Asked by dimid At
2
There are 2 best solutions below
0

No need to synchronize, the messages fill up in the buffer by FIFO concept. They keep piling up in the queue until it is completely filled. You can choose to send the message at the front of the queue by using the tx_queue_front_send
api.
When you use tx_queue_receive
you specify the ticks or time to wait for the message, until then the Threadx scheduler suspends the thread automatically, and resumes it as soon as a message arrives.
And since queues are a public resource, it can be accessed by any thread.
Any ThreadX thread can send a message to a queue and any thread can receive a message from a queue. There is no limit to how many threads can access a queue. Access from miltiple threads is already synchronized by ThreadX with FIFO discipline -- threads are resumed in the order they were suspended. However, the order can be changed with a call to the function
tx_queue_prioritize
.