Browse Source

fix pthread_join implementation

Samuel Thibault 15 years ago
parent
commit
f2e08abde9
1 changed files with 17 additions and 9 deletions
  1. 17 9
      include/pthread_win32/pthread.h

+ 17 - 9
include/pthread_win32/pthread.h

@@ -130,16 +130,24 @@ static inline void pthread_exit (void *res) {
 }
 }
 
 
 static inline int pthread_join (pthread_t thread, void **res) {
 static inline int pthread_join (pthread_t thread, void **res) {
-  DWORD _res;
+again:
-
+  switch (WaitForSingleObject(thread, INFINITE)) {
-  while (1) {
+    default:
-    if (GetExitCodeThread(thread, &_res)) {
+    case WAIT_FAILED:
-      if (res) *res = (void *)_res;
+      setSystemErrno();
-      return 0;
+      return errno;
-    }
+    case WAIT_ABANDONED:
-    winPthreadAssertWindows(GetLastError() == STILL_ACTIVE);
+    case WAIT_OBJECT_0:
-    Sleep(1);
+      break;
+    case WAIT_TIMEOUT:
+      goto again;
+  }
+  if (res) {
+    DWORD _res;
+    if (GetExitCodeThread(thread, &_res))
+      *res = (void *)_res;
   }
   }
+  return 0;
 }
 }
 
 
 /***********
 /***********