summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2022-05-25 09:36:01 +0300
committerIvan Maidanski <ivmai@mail.ru>2022-05-25 18:51:41 +0300
commite2a2e9aad923bb2288baf18aad8d38d925f56fa1 (patch)
tree396fd2b95cb20afb9b43daf4e5d61dadfa42bcd4
parentac6d028f896c3bff209a7e84fc25157a8cd55d6e (diff)
downloadbdwgc-e2a2e9aad923bb2288baf18aad8d38d925f56fa1.tar.gz
Fix assertion violation in GC_allow_register_threads on Windows
(fix of commit ab93e03de) * pthread_support.c [GC_ASSERTIONS] (GC_allow_register_threads): Wrap GC_lookup_thread() call into LOCK/UNLOCK. * win32_threads.c [GC_ASSERTIONS] (GC_allow_register_threads): Wrap GC_lookup_thread_inner() call into LOCK/UNLOCK.
-rw-r--r--pthread_support.c8
-rw-r--r--win32_threads.c10
2 files changed, 15 insertions, 3 deletions
diff --git a/pthread_support.c b/pthread_support.c
index f18a154f..ec2b5f64 100644
--- a/pthread_support.c
+++ b/pthread_support.c
@@ -2048,9 +2048,15 @@ STATIC GC_thread GC_register_my_thread_inner(const struct GC_stack_base *sb,
GC_API void GC_CALL GC_allow_register_threads(void)
{
+# ifdef GC_ASSERTIONS
+ DCL_LOCK_STATE;
+
/* Check GC is initialized and the current thread is registered. */
+ LOCK(); /* just to match that in win32_threads.c */
GC_ASSERT(GC_lookup_thread(pthread_self()) != 0);
- set_need_to_lock();
+ UNLOCK();
+# endif
+ set_need_to_lock();
}
GC_API int GC_CALL GC_register_my_thread(const struct GC_stack_base *sb)
diff --git a/win32_threads.c b/win32_threads.c
index 972b02c1..cc0ccefc 100644
--- a/win32_threads.c
+++ b/win32_threads.c
@@ -769,8 +769,14 @@ STATIC void GC_delete_thread(DWORD id)
GC_API void GC_CALL GC_allow_register_threads(void)
{
- /* Check GC is initialized and the current thread is registered. */
- GC_ASSERT(GC_lookup_thread_inner(GetCurrentThreadId()) != 0);
+# ifdef GC_ASSERTIONS
+ DCL_LOCK_STATE;
+
+ /* Check GC is initialized and the current thread is registered. */
+ LOCK();
+ GC_ASSERT(GC_lookup_thread_inner(GetCurrentThreadId()) != 0);
+ UNLOCK();
+# endif
# if !defined(GC_ALWAYS_MULTITHREADED) && !defined(PARALLEL_MARK) \
&& !defined(GC_NO_THREADS_DISCOVERY)
/* GC_init() does not call GC_init_parallel() in this case. */