summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2023-03-10 07:38:33 +0300
committerIvan Maidanski <ivmai@mail.ru>2023-03-14 17:15:52 +0300
commitbf39f18ba6e21b1f6203ccd6d34e01a6a45ac2fe (patch)
tree37de0d1a967710b7c1c9caf65ef7937849f1bc65
parent0be9aa88e639d9769ddf7c3b1d516b05878b4d04 (diff)
downloadbdwgc-bf39f18ba6e21b1f6203ccd6d34e01a6a45ac2fe.tar.gz
Fix GC_thread_is_registered for finished threads
(a cherry-pick of commit 5a8c02852 from 'master') A finished thread may still stay in GC_threads, but it is no longer considered during a garbage collection phase, thus GC_thread_is_registered() should return false in such a case. * include/gc.h [GC_THREADS] (GC_thread_is_registered): Refine comment (describe the case when the thread is marked as finished). * pthread_support.c (GC_thread_is_registered): Return FALSE if me->flags&FINISHED. * win32_threads.c (GC_thread_is_registered): Return FALSE if KNOWN_FINISHED(me).
-rw-r--r--include/gc.h2
-rw-r--r--pthread_support.c2
-rw-r--r--win32_threads.c2
3 files changed, 4 insertions, 2 deletions
diff --git a/include/gc.h b/include/gc.h
index 4336e787..942436e1 100644
--- a/include/gc.h
+++ b/include/gc.h
@@ -1321,6 +1321,8 @@ GC_API void * GC_CALL GC_call_with_stack_base(GC_stack_base_func /* fn */,
/* Return non-zero (TRUE) if and only if the calling thread is */
/* registered with the garbage collector. */
+ /* If the thread is finished (e.g. running in a destructor and not */
+ /* registered manually again), it is considered as not registered. */
GC_API int GC_CALL GC_thread_is_registered(void);
/* Unregister the current thread. Only an explicitly registered */
diff --git a/pthread_support.c b/pthread_support.c
index bab34409..d0ef211a 100644
--- a/pthread_support.c
+++ b/pthread_support.c
@@ -663,7 +663,7 @@ GC_API int GC_CALL GC_thread_is_registered(void)
LOCK();
me = GC_lookup_thread(self);
UNLOCK();
- return me != NULL;
+ return me != NULL && !(me -> flags & FINISHED);
}
#ifdef CAN_HANDLE_FORK
diff --git a/win32_threads.c b/win32_threads.c
index 6d124012..37ab3864 100644
--- a/win32_threads.c
+++ b/win32_threads.c
@@ -620,7 +620,7 @@ GC_API int GC_CALL GC_thread_is_registered(void)
LOCK();
me = GC_lookup_thread_inner(thread_id);
UNLOCK();
- return me != NULL;
+ return me != NULL && !KNOWN_FINISHED(me);
}
/* Make sure thread descriptor t is not protected by the VDB */