Index: thread_win32.c =================================================================== --- thread_win32.c (revision 46238) +++ thread_win32.c (working copy) @@ -160,8 +160,9 @@ th->native_thread_data.interrupt_event = CreateEvent(0, TRUE, FALSE, 0); - thread_debug("initial thread (th: %p, thid: %p, event: %p)\n", - th, GET_THREAD()->thread_id, + fill_thread_id_str(th); + thread_debug("initial thread (th: %p, thid: %s, event: %p)\n", + th, GET_THREAD()->thread_id_str, th->native_thread_data.interrupt_event); } @@ -583,7 +584,7 @@ native_thread_destroy(rb_thread_t *th) { HANDLE intr = InterlockedExchangePointer(&th->native_thread_data.interrupt_event, 0); - thread_debug("close handle - intr: %p, thid: %p\n", intr, th->thread_id); + thread_debug("close handle - intr: %p, thid: %s\n", intr, th->thread_id_str); w32_close_handle(intr); } @@ -597,8 +598,9 @@ th->native_thread_data.interrupt_event = CreateEvent(0, TRUE, FALSE, 0); /* run */ - thread_debug("thread created (th: %p, thid: %p, event: %p)\n", th, - th->thread_id, th->native_thread_data.interrupt_event); + fill_thread_id_str(th); + thread_debug("thread created (th: %p, thid: %s, event: %p)\n", th, + th->thread_id_str, th->native_thread_data.interrupt_event); thread_start_func_2(th, th->machine.stack_start, rb_ia64_bsp()); @@ -621,8 +623,9 @@ if (THREAD_DEBUG) { Sleep(0); - thread_debug("create: (th: %p, thid: %p, intr: %p), stack size: %"PRIdSIZE"\n", - th, th->thread_id, + fill_thread_id_str(th); + thread_debug("create: (th: %p, thid: %s, intr: %p), stack size: %"PRIdSIZE"\n", + th, th->thread_id_str, th->native_thread_data.interrupt_event, stack_size); } return 0; @@ -693,6 +696,7 @@ } static HANDLE timer_thread_id = 0; +static int timer_thread_created = 0; static HANDLE timer_thread_lock; static unsigned long __stdcall @@ -722,6 +726,7 @@ } timer_thread_id = w32_create_thread(1024 + (THREAD_DEBUG ? BUFSIZ : 0), timer_thread_func, 0); + timer_thread_created = 1; w32_resume_thread(timer_thread_id); } } @@ -735,6 +740,7 @@ native_thread_join(timer_thread_id); CloseHandle(timer_thread_lock); timer_thread_lock = 0; + timer_thread_created = 0; } return stopped; } @@ -745,6 +751,7 @@ if (timer_thread_id) { CloseHandle(timer_thread_id); timer_thread_id = 0; + timer_thread_created = 0; } } Index: thread_pthread.c =================================================================== --- thread_pthread.c (revision 46238) +++ thread_pthread.c (working copy) @@ -46,6 +46,7 @@ static void native_cond_destroy(rb_nativethread_cond_t *cond); static void rb_thread_wakeup_timer_thread_low(void); static pthread_t timer_thread_id; +static int timer_thread_created; #define RB_CONDATTR_CLOCK_MONOTONIC 1 @@ -450,6 +451,7 @@ pthread_key_create(&ruby_native_thread_key, NULL); th->thread_id = pthread_self(); + fill_thread_id_str(th); native_thread_init(th); #ifdef USE_SIGNAL_THREAD_LIST native_mutex_initialize(&signal_thread_list_lock); @@ -794,6 +796,7 @@ VALUE stack_start; #endif + fill_thread_id_str(th); #if defined USE_NATIVE_THREAD_INIT native_thread_init_stack(th); #endif @@ -954,6 +957,7 @@ native_mutex_unlock(&th->interrupt_lock); #endif thread_debug("create: %p (%d)\n", (void *)th, err); + fill_thread_id_str(th); #ifdef HAVE_PTHREAD_ATTR_INIT CHECK_ERR(pthread_attr_destroy(&attr)); #endif @@ -1153,7 +1157,7 @@ static void ubf_select_each(rb_thread_t *th) { - thread_debug("ubf_select_each (%p)\n", (void *)th->thread_id); + thread_debug("ubf_select_each (%s)\n", th->thread_id_str); if (th) { pthread_kill(th->thread_id, SIGVTALRM); } @@ -1477,7 +1481,7 @@ static void rb_thread_create_timer_thread(void) { - if (!timer_thread_id) { + if (!timer_thread_created) { int err; #ifdef HAVE_PTHREAD_ATTR_INIT pthread_attr_t attr; @@ -1507,7 +1511,7 @@ #endif /* USE_SLEEPY_TIMER_THREAD */ /* create timer thread */ - if (timer_thread_id) { + if (timer_thread_created) { rb_bug("rb_thread_create_timer_thread: Timer thread was already created\n"); } #ifdef HAVE_PTHREAD_ATTR_INIT @@ -1519,6 +1523,7 @@ fprintf(stderr, "[FATAL] Failed to create timer thread: %s\n", strerror(err)); exit(EXIT_FAILURE); } + timer_thread_created = 1; #ifdef HAVE_PTHREAD_ATTR_INIT pthread_attr_destroy(&attr); #endif @@ -1537,7 +1542,7 @@ rb_thread_wakeup_timer_thread(); native_thread_join(timer_thread_id); if (TT_DEBUG) fprintf(stderr, "joined timer thread\n"); - timer_thread_id = 0; + timer_thread_created = 0; /* close communication pipe */ if (close_anyway) { Index: vm_core.h =================================================================== --- vm_core.h (revision 46238) +++ vm_core.h (working copy) @@ -546,6 +546,7 @@ /* thread control */ rb_nativethread_id_t thread_id; + char thread_id_str[sizeof(rb_nativethread_id_t) * 2 + 3]; enum rb_thread_status status; int to_kill; int priority; Index: thread.c =================================================================== --- thread.c (revision 46238) +++ thread.c (working copy) @@ -173,6 +173,17 @@ #define POSITION_ARGS #endif +static void +fill_thread_id_str(rb_thread_t *th) +{ + size_t i; + + strncpy(&th->thread_id_str[0], "0x", 2); + for (i = 0; i < sizeof(th->thread_id); i++) { + snprintf(&th->thread_id_str[2 + i * 2], 3, "%02x", ((char *)&th->thread_id)[i]); + } +} + # if THREAD_DEBUG < 0 static int rb_thread_debug_enabled; @@ -209,6 +220,7 @@ # endif #else #define thread_debug if(0)printf +#define fill_thread_id_str(th) #endif #ifndef __ia64 @@ -792,14 +804,14 @@ else { now = timeofday(); if (now > limit) { - thread_debug("thread_join: timeout (thid: %p)\n", - (void *)target_th->thread_id); + thread_debug("thread_join: timeout (thid: %s)\n", + target_th->thread_id_str); return Qfalse; } sleep_wait_for_interrupt(th, limit - now, 0); } - thread_debug("thread_join: interrupted (thid: %p)\n", - (void *)target_th->thread_id); + thread_debug("thread_join: interrupted (thid: %s)\n", + target_th->thread_id_str); } return Qtrue; } @@ -822,7 +834,7 @@ arg.limit = timeofday() + delay; arg.forever = delay == DELAY_INFTY; - thread_debug("thread_join (thid: %p)\n", (void *)target_th->thread_id); + thread_debug("thread_join (thid: %s)\n", target_th->thread_id_str); if (target_th->status != THREAD_KILLED) { rb_thread_list_t list; @@ -835,8 +847,8 @@ } } - thread_debug("thread_join: success (thid: %p)\n", - (void *)target_th->thread_id); + thread_debug("thread_join: success (thid: %s)\n", + target_th->thread_id_str); if (target_th->errinfo != Qnil) { VALUE err = target_th->errinfo; @@ -2145,7 +2157,7 @@ rb_exit(EXIT_SUCCESS); } - thread_debug("rb_thread_kill: %p (%p)\n", (void *)th, (void *)th->thread_id); + thread_debug("rb_thread_kill: %p (%s)\n", (void *)th, th->thread_id_str); if (th == GET_THREAD()) { /* kill myself immediately */ @@ -3725,7 +3737,7 @@ void rb_thread_stop_timer_thread(int close_anyway) { - if (timer_thread_id && native_stop_timer_thread(close_anyway)) { + if (timer_thread_created && native_stop_timer_thread(close_anyway)) { native_reset_timer_thread(); } } Index: vm.c =================================================================== --- vm.c (revision 46238) +++ vm.c (working copy) @@ -2131,6 +2131,7 @@ th->last_status = Qnil; th->waiting_fd = -1; th->root_svar = Qnil; + th->thread_id_str[0] = '\0'; #if OPT_CALL_THREADED_CODE th->retval = Qundef;