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?
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.
618 Uncaught (inpromise) Error on Electron: An object could not be cloned
611 GDB gets version error when attempting to debug with the Presense SDK (IDE)
914 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
572 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.