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 11:46:51 +0300
commitf8dcf9976524972308c27d7f12a302df5c2aa111 (patch)
tree4b7014408514fb4a50d455b1b57f86ed0df08010
parentd2b01b2d0758bc0d29855431e1aab28a42198c1b (diff)
downloadbdwgc-f8dcf9976524972308c27d7f12a302df5c2aa111.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 429f6637..946162e2 100644
--- a/include/gc.h
+++ b/include/gc.h
@@ -1499,6 +1499,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);
/* Notify the collector about the stack and the alt-stack of the */
diff --git a/pthread_support.c b/pthread_support.c
index cf794e9a..b64eda0d 100644
--- a/pthread_support.c
+++ b/pthread_support.c
@@ -701,7 +701,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);
}
static pthread_t main_pthread_id;
diff --git a/win32_threads.c b/win32_threads.c
index 5ae72fb8..38560ac0 100644
--- a/win32_threads.c
+++ b/win32_threads.c
@@ -634,7 +634,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);
}
GC_API void GC_CALL GC_register_altstack(void *stack GC_ATTR_UNUSED,