mirror of
https://github.com/corda/corda.git
synced 2025-01-21 03:55:00 +00:00
Thread.sleep(0) should not sleep indefinitely
Our implementation uses Object.wait(long) to implement Thread.sleep, which had the side effect of interpreting zero as infinity. However, for Thread.sleep, zero just means zero. I assume that doesn't mean "don't sleep at all", though, or else the app wouldn't have called Thread.sleep in the first place, so this patch sleeps for one millisecond when zero is passed -- just enough to yield the processor for a bit. Thread.yield might be a better choice in this case, but I assume the app would have called that directly if that's what it wanted.
This commit is contained in:
parent
f8e860999a
commit
47503854d5
@ -156,6 +156,10 @@ public class Thread implements Runnable {
|
||||
}
|
||||
|
||||
public static void sleep(long milliseconds) throws InterruptedException {
|
||||
if (milliseconds <= 0) {
|
||||
milliseconds = 1;
|
||||
}
|
||||
|
||||
Thread t = currentThread();
|
||||
if (t.sleepLock == null) {
|
||||
t.sleepLock = new Object();
|
||||
|
@ -3309,6 +3309,10 @@ jvmSleep(Thread* t, uintptr_t* arguments)
|
||||
{
|
||||
jlong milliseconds; memcpy(&milliseconds, arguments, sizeof(jlong));
|
||||
|
||||
if (milliseconds <= 0) {
|
||||
milliseconds = 1;
|
||||
}
|
||||
|
||||
if (threadSleepLock(t, t->javaThread) == 0) {
|
||||
object lock = makeJobject(t);
|
||||
set(t, t->javaThread, ThreadSleepLock, lock);
|
||||
|
Loading…
Reference in New Issue
Block a user