- for (int i = 0; i <= MAX_THREADS; i++)
- {
- threads[i].do_terminate = true; // Search must be already finished
- threads[i].wake_up();
-
- // Wait for thread termination
-#if defined(_MSC_VER)
- WaitForSingleObject(threads[i].handle, INFINITE);
- CloseHandle(threads[i].handle);
-#else
- pthread_join(threads[i].handle, NULL);
-#endif
-
- // Now we can safely destroy associated locks and wait conditions
- lock_destroy(&threads[i].sleepLock);
- cond_destroy(&threads[i].sleepCond);
-
- for (int j = 0; j < MAX_ACTIVE_SPLIT_POINTS; j++)
- lock_destroy(&(threads[i].splitPoints[j].lock));
- }
-
- lock_destroy(&threadsLock);
- cond_destroy(&sleepCond);