Avoid throwing interrupted exception in JoinThread

I saw a stacktrace when exiting sbtn on windows due to an interrupted
exception being thrown during thread joining. We only want to throw this
exception if we didn't successfully join the thread. I also noticed that
we would try to join the thread forever. There was supposed to be a
timelimit so that we would eventually stop blocking even if we were
unable to join the thread. The limit was set but not respected.
This commit is contained in:
Ethan Atkins 2020-10-25 15:07:24 -07:00
parent b5fc17cc7a
commit c66f31d8a1
1 changed files with 5 additions and 3 deletions

View File

@ -20,11 +20,13 @@ object JoinThread {
t.interrupt()
t.join(10)
} catch { case e: InterruptedException => exception = Some(e) }
if (t.isAlive) impl()
if (t.isAlive && !deadline.isOverdue) impl()
}
impl()
if (t.isAlive) System.err.println(s"Unable to join thread $t after $duration")
exception.foreach(throw _)
if (t.isAlive) {
System.err.println(s"Unable to join thread $t after $duration")
exception.foreach(throw _)
}
}
}
}