From 0f4e6e938e9d53693d37dd1fb7a03c534df80c4e Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Wed, 27 Sep 2017 10:52:09 +0300 Subject: [PATCH] Fix pthread_detach for threads not yet registered (Cygwin, winpthreads) (Cherry-pick commit 45bf28f from 'release-7_4' branch.) * 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 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/win32_threads.c b/win32_threads.c index d853240c..b4257579 100644 --- a/win32_threads.c +++ b/win32_threads.c @@ -2574,7 +2574,10 @@ GC_INNER void GC_thr_init(void) DCL_LOCK_STATE; if (!parallel_initialized) GC_init_parallel(); - 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) { LOCK(); -- 2.40.0