From 7d4c5e3e78c47ae64b97c24ba1145b13c1137e26 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Fri, 25 Aug 2017 01:05:16 +0300 Subject: [PATCH] Add debug logging to new_thread about GC_threads hash table collisions * pthread_support.c [DEBUG_THREADS] (GC_new_thread): Call GC_log_printf (with the appropriate message) if a GC_threads[] entry already exists at the given hv index (excluding the detached threads those id is already reused). * win32_threads.c [DEBUG_THREADS] (GC_new_thread): Call GC_log_printf to report that a new thread is created; call GC_log_printf (with the appropriate message) if a GC_threads[] entry already exists at the given hv index; remove useless comment about the result of GC_INTERNAL_MALLOC. --- pthread_support.c | 5 +++++ win32_threads.c | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pthread_support.c b/pthread_support.c index 00032617..7b02d95c 100644 --- a/pthread_support.c +++ b/pthread_support.c @@ -543,6 +543,11 @@ STATIC GC_thread GC_new_thread(pthread_t id) # ifdef DEBUG_THREADS GC_log_printf("Creating thread %p\n", (void *)id); + for (result = GC_threads[hv]; result != NULL; result = result->next) + if (!THREAD_EQUAL(result->id, id)) { + GC_log_printf("Hash collision at GC_threads[%d]\n", hv); + break; + } # endif GC_ASSERT(I_HOLD_LOCK()); if (!EXPECT(first_thread_used, TRUE)) { diff --git a/win32_threads.c b/win32_threads.c index bce8af93..7befb9bb 100644 --- a/win32_threads.c +++ b/win32_threads.c @@ -338,6 +338,11 @@ STATIC GC_thread GC_new_thread(DWORD id) int hv = THREAD_TABLE_INDEX(id); GC_thread result; +# ifdef DEBUG_THREADS + GC_log_printf("Creating thread 0x%lx\n", (long)id); + if (GC_threads[hv] != NULL) + GC_log_printf("Hash collision at GC_threads[%d]\n", hv); +# endif GC_ASSERT(I_HOLD_LOCK()); if (!EXPECT(first_thread_used, TRUE)) { result = &first_thread; @@ -346,7 +351,6 @@ STATIC GC_thread GC_new_thread(DWORD id) GC_ASSERT(!GC_win32_dll_threads); result = (struct GC_Thread_Rep *) GC_INTERNAL_MALLOC(sizeof(struct GC_Thread_Rep), NORMAL); - /* result can be NULL */ if (result == 0) return(0); } /* result -> id = id; Done by caller. */ -- 2.40.0