On 29 May 2015, at 16:57, Emmanuel Dreyfus <m...@netbsd.org> wrote:

> On Fri, May 29, 2015 at 04:26:33PM +0200, J. Hannken-Illjes wrote:
>> With this change some programs fail with
>> 
>>      assertion "pthread__tsd_destructors[key] != NULL" failed
>>      file src/lib/libpthread/pthread_tsd.c", line 169,
>>      function "pthread__add_specific"
>> 
>> Machine is amd64, 16 cores, KVM host.  Among others "gunzip" fails.
>> Reverting this commit removes the failure.
> 
> I have seen that with older libc: setting breackpoints on 
> pthread_key_create() and pthread_setspecific() shows that malloc()
> calls the later without calling the former, which is a bug. It
> worked before previously, pthread__tsd_destructors[] was not zero'ed 
> and contained random data. I tested filling the array with non NULL 
> random data and the assertion is not fired anymore.
> 
> More recent libc did not seem to have the problem. How old is yours?

May 29 11:50 /lib/libc.so.12.197 from after your commit.

> Can you confirm the pthread_key_create()/pthread_setspecific() test?

As I can't install (no gunzip ...) I can't run tests.

Reverting your commit and adding the attached patch I get:

gunzip < /sets/kern-work.tgz > /dev/null
[ pthread__init ]
[ pthread_key_create : 0 / 0x7f7ff640759c ]
[ pthread__add_specific : 0 / 0x7f7ff640759c ]

Debug patch:

--- pthread.c   16 Dec 2014 20:05:54 -0000      1.145
+++ pthread.c   29 May 2015 16:11:34 -0000
@@ -233,4 +233,5 @@ pthread__init(void)
        pthread_atfork(NULL, NULL, pthread__fork_callback);
        __isthreaded = 1;
+fprintf(stderr, "[ %s ]\n", __func__);
 }
 

--- pthread_tsd.c       21 Mar 2013 16:49:12 -0000      1.11
+++ pthread_tsd.c       29 May 2015 16:11:34 -0000
@@ -35,4 +35,5 @@ __RCSID("$NetBSD: pthread_tsd.c,v 1.11 2
 /* Functions and structures dealing with thread-specific data */
 #include <errno.h>
+#include <stdio.h>
 
 #include "pthread.h"
@@ -92,4 +93,5 @@ pthread_key_create(pthread_key_t *key, v
                         * to be found.
                         */
+fprintf(stderr, "[ %s -> EAGAIN ]\n", __func__);
                        pthread_mutex_unlock(&tsd_mutex);
                        return EAGAIN;
@@ -100,4 +102,5 @@ pthread_key_create(pthread_key_t *key, v
        pthread__assert(PTQ_EMPTY(&pthread__tsd_list[i]));
        pthread__tsd_destructors[i] = destructor ? destructor : null_destructor;
+fprintf(stderr, "[ %s : %d / %p ]\n", __func__, i, 
pthread__tsd_destructors[i]);
 
        nextkey = (i + 1) % PTHREAD_KEYS_MAX;
@@ -134,4 +137,6 @@ pthread__add_specific(pthread_t self, pt
 
        pthread_mutex_lock(&tsd_mutex);
+fprintf(stderr, "[ %s : %d / %p ]\n", __func__, key,
+    pthread__tsd_destructors[key]);
        pthread__assert(pthread__tsd_destructors[key] != NULL);
        pt = &self->pt_specific[key];

--
J. Hannken-Illjes - hann...@eis.cs.tu-bs.de - TU Braunschweig (Germany)

Reply via email to