Ensure that event listener thread does not join on itself

This commit is contained in:
Will Hedgecock 2022-02-16 16:14:47 -06:00
parent 96a47bcad8
commit ea3c593776
1 changed files with 10 additions and 9 deletions

View File

@ -1758,17 +1758,18 @@ public final class SerialPort
eventListenerRunning = false;
configTimeouts(portHandle, TIMEOUT_NONBLOCKING, 0, 0, 0);
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
{
// Wait until the event-reading thread returns. This thread MUST return or the serial port will
// be in an unspecified, possibly unrecoverable state
do
{
serialEventThread.join(500);
if (serialEventThread.isAlive())
serialEventThread.interrupt();
} while (serialEventThread.isAlive());
if (!Thread.currentThread().equals(serialEventThread))
do
{
serialEventThread.join(500);
if (serialEventThread.isAlive())
serialEventThread.interrupt();
} while (serialEventThread.isAlive());
}
catch (InterruptedException e) { Thread.currentThread().interrupt(); }
serialEventThread = null;