Open rocketraman opened 2 years ago
this is already documented as limitation in the code: https://github.com/mik3y/usb-serial-for-android/blob/5bb8db02d5a6f2db32522ce602a6dd7d791de083/usbSerialForAndroid/src/main/java/com/hoho/android/usbserial/util/SerialInputOutputManager.java#L147 I recommend to do writing directly in your worker thread
I recommend to do writing directly in your worker thread
That's totally understood -- in fact I ended up dumping the SerialInputOutputManager
and doing both writes and reads myself to keep things consistent and clean, and I prefer doing the reads and writes in separate threads, and asynchronously via coroutines. Now I am just using usb-serial-for-android to do the serial-specific stuff like line initialization, for which it has been invaluable!
However, the point of this issue was for future users of this library to not have to take this step by changing SerialInputOutputManager
to avoid the potential read/write deadlock -- why not use separate reader and writer threads in SerialInputOutputManager
?
The
SerialInputOutputManager
currently potentially does an no-timeout read (depending on the timeout settings) before write in each step. If the read data depends on something being written, this results in a deadlock.