Ensure that event listener thread does not join on itself
This commit is contained in:
parent
96a47bcad8
commit
ea3c593776
|
@ -1758,17 +1758,18 @@ public final class SerialPort
|
||||||
eventListenerRunning = false;
|
eventListenerRunning = false;
|
||||||
configTimeouts(portHandle, TIMEOUT_NONBLOCKING, 0, 0, 0);
|
configTimeouts(portHandle, TIMEOUT_NONBLOCKING, 0, 0, 0);
|
||||||
setEventListeningStatus(portHandle, false);
|
setEventListeningStatus(portHandle, false);
|
||||||
|
|
||||||
|
// Wait until the event-reading thread returns. This thread MUST return or the serial port will
|
||||||
|
// be in an unspecified, possibly unrecoverable state
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Wait until the event-reading thread returns. This thread MUST return or the serial port will
|
if (!Thread.currentThread().equals(serialEventThread))
|
||||||
// be in an unspecified, possibly unrecoverable state
|
do
|
||||||
do
|
{
|
||||||
{
|
serialEventThread.join(500);
|
||||||
serialEventThread.join(500);
|
if (serialEventThread.isAlive())
|
||||||
if (serialEventThread.isAlive())
|
serialEventThread.interrupt();
|
||||||
serialEventThread.interrupt();
|
} while (serialEventThread.isAlive());
|
||||||
} while (serialEventThread.isAlive());
|
|
||||||
}
|
}
|
||||||
catch (InterruptedException e) { Thread.currentThread().interrupt(); }
|
catch (InterruptedException e) { Thread.currentThread().interrupt(); }
|
||||||
serialEventThread = null;
|
serialEventThread = null;
|
||||||
|
|
Loading…
Reference in New Issue