static void runQuickSort(int[] a, int N, int approxNumThreads) throws InterruptedException { Global.shuffleArray(a); double timePassed = System.currentTimeMillis(); Global.allThreads = new ArrayList<quicksortThread>(); quicksortThread main_qsth = new quicksortThread( a, 0, N - 1, (int) (N / (double) (approxNumThreads / 1.95)), false); // 1.95 was calculated approximately; it's got to do with the log of the // quicksort, and is the average branching factor?? Global.allThreads.add(main_qsth); main_qsth.start(); boolean done = false; int thcount = 1; while (!done) { done = true; thcount = Global.max(thcount, Global.allThreads.size()); for (int i = 0; i < Global.allThreads.size(); i++) { if (Global.allThreads.get(i) != null && Global.allThreads.get(i).getState() != Thread.State.TERMINATED) { done = false; break; } } Thread.sleep(1); } timePassed = System.currentTimeMillis() - timePassed; timePassed = ((double) timePassed) / 1000; // Thread.sleep(1000); // Global.printArray(a, N, "Sorted array"); // Global.isArraySorted(a,N); Global.timePassed = timePassed; Global.thcount = thcount; }