* include/arch/win32/apr_arch_threadproc.h
  (apr_thread_t): New status variable to indicate a terminated thread

* test/testatomic.c
  (test_atomics_threaded): Check the return code from apr_thread_join

* threadproc/win32/thread.c
(apr_thread_create): Initialize the status variable
(apr_thread_exit): Set the terminated status if the thread is not detached
(apr_thread_join): If the wait fails, look whether the thread was
already terminated.


Index: include/arch/win32/apr_arch_threadproc.h
===================================================================
RCS file: /home/cvspublic/apr/include/arch/win32/apr_arch_threadproc.h,v
retrieving revision 1.3
diff -u -3 -r1.3 apr_arch_threadproc.h
--- include/arch/win32/apr_arch_threadproc.h    1 Mar 2004 21:05:44 -0000       
1.3
+++ include/arch/win32/apr_arch_threadproc.h    6 Apr 2004 15:53:17 -0000
@@ -30,6 +30,7 @@
     void *data;
     apr_thread_start_t func;
     apr_status_t exitval;
+    long terminated;    
 };
 
 struct apr_threadattr_t {
Index: test/testatomic.c
===================================================================
RCS file: /home/cvspublic/apr/test/testatomic.c,v
retrieving revision 1.43
diff -u -3 -r1.43 testatomic.c
--- test/testatomic.c   13 Mar 2004 01:51:59 -0000      1.43
+++ test/testatomic.c   6 Apr 2004 15:53:18 -0000
@@ -255,9 +255,16 @@
     }
 
     for (i = 0; i < NUM_THREADS; i++) {
-        apr_thread_join(&s1[i], t1[i]);
-        apr_thread_join(&s2[i], t2[i]);
-        apr_thread_join(&s3[i], t3[i]);
+        apr_status_t r;
+
+        r = apr_thread_join(&s1[i], t1[i]);
+        CuAssertIntEquals(tc, APR_SUCCESS, r);
+
+        r = apr_thread_join(&s2[i], t2[i]);
+        CuAssertIntEquals(tc, APR_SUCCESS, r);
+
+        r = apr_thread_join(&s3[i], t3[i]);
+        CuAssertIntEquals(tc, APR_SUCCESS, r);
                      
         CuAssert(tc, "Invalid return value from thread_join",
                  s1[i] == exit_ret_val && s2[i] == exit_ret_val && 
Index: threadproc/win32/thread.c
===================================================================
RCS file: /home/cvspublic/apr/threadproc/win32/thread.c,v
retrieving revision 1.56
diff -u -3 -r1.56 thread.c
--- threadproc/win32/thread.c   1 Mar 2004 21:05:44 -0000       1.56
+++ threadproc/win32/thread.c   6 Apr 2004 15:53:19 -0000
@@ -89,6 +89,7 @@
     (*new)->pool = pool;
     (*new)->data = data;
     (*new)->func = func;
+    (*new)->terminated = 0;
     
     stat = apr_pool_create(&(*new)->pool, pool);
     if (stat != APR_SUCCESS) {
@@ -128,7 +129,9 @@
     apr_pool_destroy(thd->pool);
 #ifndef _WIN32_WCE
     if (thd->td) {
+        thd->terminated = 1;
         CloseHandle(thd->td);
+        thd->td = NULL;
     }
     _endthreadex(0);
 #else
@@ -147,6 +150,14 @@
         *retval = thd->exitval;
         return APR_SUCCESS;
     }
+
+    /* Thread already terminated ? */
+    if (thd->terminated)
+    {
+        *retval = thd->exitval;
+        return APR_SUCCESS;
+    }
+
     /* Wait failed */
     return apr_get_os_error();;
 }

Reply via email to