To my frustration, people have reported all sorts of problems compiling and running my recent development versions of Glaurung with support for more than 2 threads under Windows, although it works fine in Linux and Mac OS X. I have now found that the reason is probably a really silly bug in the Windows version of my thread initialisation code. I have tried to correct it, but as I don't run Windows myself I cannot test the code. Can someone with at least superficial knowledge about POSIX and Windows threads confirm whether the following POSIX and Windows code are correct "translations" of each other?
POSIX:
- Code: Select all
void idle_loop(int thread_id, split_point_t *wait_sp);
static void *init_thread(void *thread_id) {
idle_loop(*(int *)thread_id, NULL); return NULL;
}
void init_threads(int n) {
// Lots of code snipped here
for(i = 1; i < n; i++) {
pthread_create(pthread, NULL, init_thread, (void *)(&i));
// Wait until the thread has finished launching:
while(!Threads[i].running);
}
// Lots of code snipped here
}
Windows:
- Code: Select all
void idle_loop(int thread_id, split_point_t *wait_sp);
static DWORD WINAPI win_init_thread(LPVOID thread_id) {
idle_loop(*(int *)thread_id, NULL); return 0;
}
void init_threads(int n) {
// Lots of code snipped here
for(i = 1; i < n; i++) {
DWORD iID[1];
CreateThread(NULL, 0, win_init_thread, (LPVOID)(&i), 0, iID);
// Wait until the thread has finished launching:
while(!Threads[i].running);
}
// Lots of code snipped here
}
It would also be nice if someone with the Microsoft compiler could try to compile my current development version and let me know whether it works.
Tord