threads[i].threadID = i;
#if defined(_MSC_VER)
- bool ok = (CreateThread(NULL, 0, start_routine, (LPVOID)&threads[i].threadID , 0, NULL) != NULL);
+ threads[i].handle = CreateThread(NULL, 0, start_routine, (LPVOID)&threads[i].threadID, 0, NULL);
+ bool ok = (threads[i].handle != NULL);
#else
- pthread_t pthreadID;
- bool ok = (pthread_create(&pthreadID, NULL, start_routine, (void*)&threads[i].threadID) == 0);
- pthread_detach(pthreadID);
+ bool ok = (pthread_create(&threads[i].handle, NULL, start_routine, (void*)&threads[i].threadID) == 0);
#endif
+
if (!ok)
{
std::cout << "Failed to create thread number " << i << std::endl;
{
threads[i].do_terminate = true;
threads[i].wake_up();
- while (threads[i].state != Thread::TERMINATED) {}
+
+#if defined(_MSC_VER)
+ WaitForSingleObject(threads[i].handle, 0);
+ CloseHandle(threads[i].handle);
+#else
+ pthread_join(threads[i].handle, NULL);
+ pthread_detach(threads[i].handle);
+#endif
}
// Now we can safely destroy locks and wait conditions
enum ThreadState
{
- SEARCHING, // Thread is performing work
AVAILABLE, // Thread is waiting for work
WORKISWAITING, // Master has ordered us to start searching
- TERMINATED // We are quitting and thread is terminated
+ SEARCHING // Thread is performing work
};
void wake_up();
volatile int activeSplitPoints;
volatile bool do_sleep;
volatile bool do_terminate;
+
+#if defined(_MSC_VER)
+ HANDLE handle;
+#else
+ pthread_t handle;
+#endif
};