Skip to content

Commit 2ac8911

Browse files
author
tk
committed
Fix Bugs listed by Sonar Qube.
1 parent 54f88e0 commit 2ac8911

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

cuckoo-uci/src/main/java/org/petero/cuckoo/uci/EngineControl.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ public final void ponderHit() {
159159
}
160160
infinite = (maxTimeLimit < 0) && (maxDepth < 0) && (maxNodes < 0);
161161
ponder = false;
162+
synchronized (threadMutex) {
163+
threadMutex.notifyAll();
164+
}
162165
}
163166

164167
public final void stopSearch() {
@@ -239,7 +242,7 @@ private void startThread(final int minTimeLimit, final int maxTimeLimit, int max
239242
}
240243
tt.nextGeneration();
241244
final int srchmaxDepth = maxDepth;
242-
engineThread = Thread.ofVirtual().start(() -> {
245+
engineThread = new Thread(() -> {
243246
Move m = null;
244247
if (ownBook && !analyseMode) {
245248
Book book = new Book(false);
@@ -248,14 +251,17 @@ private void startThread(final int minTimeLimit, final int maxTimeLimit, int max
248251
if (m == null) {
249252
m = sc.iterativeDeepening(srchMoves, srchmaxDepth, maxNodes, false);
250253
}
251-
while (ponder || infinite) {
254+
252255
// We should not respond until told to do so. Just wait
253256
// until
254257
// we are allowed to respond.
255-
try {
256-
Thread.sleep(10);
257-
} catch (InterruptedException ex) {
258-
break;
258+
synchronized (threadMutex) {
259+
while (ponder || infinite) {
260+
try {
261+
threadMutex.wait();
262+
} catch (InterruptedException ex) {
263+
Thread.currentThread().interrupt();
264+
}
259265
}
260266
}
261267
Move ponderMove = getPonderMove(pos, m);

0 commit comments

Comments
 (0)