public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
* pthread_key_create destructor
@ 2003-01-03 15:30 Thomas Beckmann
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Beckmann @ 2003-01-03 15:30 UTC (permalink / raw)
  To: pthreads-win32

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* RE: pthread_key_create destructor
@ 2003-01-06 14:48 Bossom, John
  0 siblings, 0 replies; 2+ messages in thread
From: Bossom, John @ 2003-01-06 14:48 UTC (permalink / raw)
  To: 'beckmann.bremen@t-online.de', pthreads-win32

Note:

You need to call pthread_exit() in your example... you should
be able to find documentation in several books that indicate
that you need to do this to ensure the key destructors are
called on the main thread of execution
(i.e. this is not a pthread-win32 specific thing)

Cheers,
John

-----Original Message-----
From: beckmann.bremen@t-online.de [mailto:beckmann.bremen@t-online.de]
Sent: Friday, January 03, 2003 10:30 AM
To: pthreads-win32@sources.redhat.com
Subject: pthread_key_create destructor


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

This message may contain privileged and/or confidential information.  If you
have received this e-mail in error or are not the intended recipient, you
may not use, copy, disseminate or distribute it; do not open any
attachments, delete it immediately from your system and notify the sender
promptly by e-mail that you have done so.  Thank you.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-01-06 14:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-03 15:30 pthread_key_create destructor Thomas Beckmann
2003-01-06 14:48 Bossom, John

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).