]> granicus.if.org Git - gc/commitdiff
Fix pthread_detach for threads not yet registered (Cygwin, winpthreads)
authorIvan Maidanski <ivmai@mail.ru>
Wed, 27 Sep 2017 07:52:09 +0000 (10:52 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Thu, 28 Sep 2017 08:55:23 +0000 (11:55 +0300)
* win32_threads.c [GC_PTHREADS] (GC_pthread_detach): Repeat
GC_lookup_pthread() (with a 10 msec delay) while t is null; add comment
and TODO; remove ABORT if t is null (as t is never null after
pthread_detach call).

win32_threads.c

index 7313c78cd49cd6125967e78ad5d8bcc85ff133a6..5a41a7961a69820fe7c3ef9c26b869e6c182677d 100644 (file)
@@ -2716,10 +2716,12 @@ GC_INNER void GC_thr_init(void)
     DCL_LOCK_STATE;
 
     GC_ASSERT(!GC_win32_dll_threads);
-    t = GC_lookup_pthread(thread);
+    /* The thread might not have registered itself yet. */
+    /* TODO: Wait for registration of the created thread in pthread_create. */
+    while ((t = GC_lookup_pthread(thread)) == NULL)
+      Sleep(10);
     result = pthread_detach(thread);
     if (result == 0) {
-      if (NULL == t) ABORT("Thread not registered");
       LOCK();
       t -> flags |= DETACHED;
       /* Here the pthread thread id may have been recycled. */