This is the mail archive of the mailing list for the pthreas-win32 project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

pthread_key_create destructor


I have a problem with pthread_key_create ().
I'm using the latest(2002-11-4) pre-build pthreadVC.dll on Windows XP with MSVC++ 6.0.
I wrote the following example to explain the problem:

#include <pthread.h>
#include <windows.h>
#include <stdio.h>

pthread_key_t key;

void destructor (void *ptr)
printf ((char*)ptr);
free (ptr);

int main (int argc, char *argv[])
char *ptr;

pthread_key_create (&key, &destructor);
if ((ptr = pthread_getspecific(key)) == NULL) {
ptr = strdup ("test\n");
pthread_setspecific (key, ptr);
return 0;

I think, this is a valid example, and it works fine as a release version but the debug version crashes inside the destructor() function .
The address of ptr inside destructor() is the same as inside main() but when having a look at the memory pointed to by ptr, it is initialized to zero at the end of main but unspecified inside of destructor().
It seems, that the address of ptr is already outside the applications address space or somehow else invalid, so the destructor is called too late.

Thanks for any help,

Thomas Beckmann

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]