From 647800330a9e1fbad8e74eb65cadb539ff61feaa Mon Sep 17 00:00:00 2001 From: SayantanScience <62644027+SayantanScience@users.noreply.github.com> Date: Wed, 24 Aug 2022 17:17:26 +0530 Subject: [PATCH] Removed unnecessary synchronisation Search.solution was unnecessarily synchronising its operations. The only part where it needs synchronisation is the init part. So, we add a (unsynchronized) check there. This will cause the first call in each thread to try to init, but only one thread will get the lock on CoordCube.class and init it. After this init phase, the process will become completely lock-free(actually this is the double-check idiom) --- src/Search.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Search.java b/src/Search.java index 5d563f8..bff7866 100644 --- a/src/Search.java +++ b/src/Search.java @@ -172,7 +172,7 @@ public Search() { * Error 7: No solution exists for the given maxDepth
* Error 8: Probe limit exceeded, no solution within given probMax */ - public synchronized String solution(String facelets, int maxDepth, long probeMax, long probeMin, int verbose) { + public String solution(String facelets, int maxDepth, long probeMax, long probeMin, int verbose) { int check = verify(facelets); if (check != 0) { return "Error " + Math.abs(check); @@ -184,8 +184,10 @@ public synchronized String solution(String facelets, int maxDepth, long probeMax this.verbose = verbose; this.solution = null; this.isRec = false; - - CoordCube.init(false); + + if(CoordCube.initLevel==0){ + CoordCube.init(false); + } initSearch(); return (verbose & OPTIMAL_SOLUTION) == 0 ? search() : searchopt();