public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
From: beckmann.bremen@t-online.de (Thomas Beckmann)
To: pthreads-win32@sources.redhat.com
Subject: pthread_key_create destructor
Date: Fri, 03 Jan 2003 15:30:00 -0000	[thread overview]
Message-ID: <5.1.0.14.0.20030103155101.00c88690@pop.t-online.de> (raw)

Hi,

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

             reply	other threads:[~2003-01-03 15:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-03 15:30 Thomas Beckmann [this message]
2003-01-06 14:48 Bossom, John

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5.1.0.14.0.20030103155101.00c88690@pop.t-online.de \
    --to=beckmann.bremen@t-online.de \
    --cc=pthreads-win32@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).