DroidFish: Don't run GTB initialization and engine startup in parallel. Seems to trigger ICS bug, see http://stackoverflow.com/questions/8688382/runtime-exec-bug-hangs-without-providing-a-process-object.

This commit is contained in:
Peter Osterlund
2012-05-12 18:16:38 +00:00
parent 51278dfc35
commit f49809fa7f
3 changed files with 14 additions and 2 deletions

View File

@@ -46,4 +46,7 @@ public class EngineUtil {
/** Executes chmod 744 exePath. */
final static native boolean chmod(String exePath);
/** For synchronizing non thread safe native calls. */
public static Object nativeLock = new Object();
}

View File

@@ -69,7 +69,9 @@ public class ExternalEngine extends UCIEngineBase {
copyFile(engineFileName, new File(exePath));
chmod(exePath);
ProcessBuilder pb = new ProcessBuilder(exePath);
engineProc = pb.start();
synchronized (EngineUtil.nativeLock) {
engineProc = pb.start();
}
startupThread = new Thread(new Runnable() {
@Override

View File

@@ -20,6 +20,8 @@ package org.petero.droidfish.gtb;
import java.util.concurrent.ConcurrentLinkedQueue;
import org.petero.droidfish.engine.EngineUtil;
/** Interface to native gtb probing code. */
class GtbProbe {
static {
@@ -38,6 +40,9 @@ class GtbProbe {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
// Sleep 0.5s to increase probability that engine
// is initialized before TB.
try { Thread.sleep(500); } catch (InterruptedException e) { }
initIfNeeded();
}
});
@@ -52,7 +57,9 @@ class GtbProbe {
path = tbPathQueue.poll();
if (path != null) {
currTbPath = path;
init(currTbPath);
synchronized (EngineUtil.nativeLock) {
init(currTbPath);
}
}
}