nyholku / purejavacomm

Pure Java implementation of JavaComm SerialPort
http://www.sparetimelabs.com/purejavacomm/index.html
BSD 3-Clause "New" or "Revised" License
362 stars 146 forks source link

jtermios.windows.JTermiosImpl$Fail when using multiple Threads #130

Open Siebje opened 4 years ago

Siebje commented 4 years ago

I encountered a problem when using multiple threads, and to be honest, I'm not sure if this is a bug in the library or Windows being silly. However, I feel like it could be a solvable issue.

The problem is that it seems to be okay to write to a port from different threads as long as all threads stay alive in the lifetime of the connection. If any of the threads die while the port is open, jtermios.windows.JTermiosImpl$Fail is thrown.

I have included a testcase that can reliably reproduce the issue. Simply connect a loopback port (I used an FTDI cable with TX and RX shorted) and run the test. You'll see that if I keep the thread alive, all is fine, but if the thread finishes, the error occurs. ComThreading.java.txt