- // This flag is needed to properly end the threads when program exits
- allThreadsShouldExit = false;
+ activeThreads = cnt;
+
+ for (int i = 0; i < MAX_THREADS; i++)
+ if (i < activeThreads)
+ {
+ // Dynamically allocate pawn and material hash tables according to the
+ // number of active threads. This avoids preallocating memory for all
+ // possible threads if only few are used as, for instance, on mobile
+ // devices where memory is scarce and allocating for MAX_THREADS could
+ // even result in a crash.
+ threads[i].pawnTable.init();
+ threads[i].materialTable.init();
+
+ threads[i].do_sleep = false;
+ }
+ else
+ threads[i].do_sleep = true;
+}