About Boot Serial Communications

Asked 2 years ago, Updated 2 years ago, 84 views

I created a serial communication program using this site as a reference.
http://chicklab.blog84.fc2.com/blog-entry-29.html
Suppose that the thread writes at a certain period, e.g. every 20 Hz,
I would like to use the same port on a different thread and write at any time.
If you are called at the same time, you will be competing, right?
Think about using boot::asio::strand to make it thread safe.
I thought about managing the flag, but it doesn't work
Is there any good way?

c++ boost

2022-09-30 21:10

1 Answers

Empirically, reading/write from multiple threads for one port or separating read and write into separate threads is complicated to implement.
In this case, create a single thread to read/write all the ports from the thread hoge.If you want to read/write from another thread to the port, you can use queue and so on to send a request to thread A, and the actual read/write operation to the port can be described in the thread hoge to facilitate exclusive control and state transition implementation.


2022-09-30 21:10

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.