From e2b67d2873ca895011d95f78d626c5c85a515d6f Mon Sep 17 00:00:00 2001 From: rfm Date: Tue, 14 Jul 2015 18:05:55 +0000 Subject: [PATCH] improve logging of threwad id on premature exit git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@38791 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 1 + Source/NSThread.m | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 663451d07..dc25152a0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,7 @@ with software expecting to validate using that dtd. Stefan Bidigaray pointed out that the heading we currently write is very out of date. + * Source/NSThread.m: On premature thread exist, log native thread ID. 2015-07-09 Richard Frith-Macdonald diff --git a/Source/NSThread.m b/Source/NSThread.m index 767611f53..00cdc799c 100644 --- a/Source/NSThread.m +++ b/Source/NSThread.m @@ -119,7 +119,7 @@ GSPrivateThreadID() #elif defined(HAVE_GETTID) return (NSUInteger)syscall(SYS_gettid); #elif defined(HAVE_PTHREAD_GETTHREADID_NP) - return pthread_getthreadid_np(); + return (NSUInteger)pthread_getthreadid_np(); #else return (NSUInteger)GSCurrentThread(); #endif @@ -412,8 +412,20 @@ static void exitedThread(void *thread) { if (thread != defaultThread) { - fprintf(stderr, "WARNING thread %p terminated without calling +exit!\n", - thread); + NSUInteger tid; + +#if defined(__MINGW__) + tid = (NSUInteger)GetCurrentThreadId(); +#elif defined(HAVE_GETTID) + tid = (NSUInteger)syscall(SYS_gettid); +#elif defined(HAVE_PTHREAD_GETTHREADID_NP) + tid = (NSUInteger)pthread_getthreadid_np(); +#else + tid = (NSUInteger)thread; +#endif + + fprintf(stderr, "WARNING thread %"PRIuPTR + " terminated without calling +exit!\n", tid); } } @@ -796,8 +808,8 @@ unregisterActiveThread(NSThread *thread) - (NSString*) description { - return [NSString stringWithFormat: @"%@{name = %@, num = %llu}", - [super description], _name, (unsigned long long)GSPrivateThreadID()]; + return [NSString stringWithFormat: @"%@{name = %@, num = %"PRIuPTR"}", + [super description], _name, GSPrivateThreadID()]; } - (id) init