Re: mutex PTHREAD_MUTEX_ERRORCHECK and pthread_cancel issues
Re: mutex PTHREAD_MUTEX_ERRORCHECK and pthread_cancel issues
- Subject: Re: mutex PTHREAD_MUTEX_ERRORCHECK and pthread_cancel issues
- From: Matt Watson <email@hidden>
- Date: Thu, 12 May 2005 13:27:12 -0700
On May 12, 2005, at 11:25 AM, Stéphane Letz wrote:
But after a pthread_cancel() has been called, the
__pthread_destructor code is never called. Is there any known issue
in using the pthread_key_create system?
Are you sure your code has reached a cancellation point?
The following works fine for me on Tiger:
% cat test.c
#include <assert.h>
#include <pthread.h>
#include <stdio.h>
static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t c = PTHREAD_COND_INITIALIZER;
static pthread_key_t k;
void *
func(void *arg)
{
assert(!pthread_setspecific(k, arg));
assert(!pthread_mutex_lock(&m));
while (1) {
assert(!pthread_cond_wait(&c, &m));
}
/* NOT REACHED */
assert(!pthread_mutex_unlock(&m));
return NULL;
}
void cleanup_func(void *arg)
{
printf("cleanup called with %p\n", arg);
}
int
main(void)
{
pthread_t t;
int i = 42;
void *ret;
assert(!pthread_key_create(&k, cleanup_func));
printf("creating a thread with arg %p\n", &i);
assert(!pthread_create(&t, NULL, func, &i));
assert(!pthread_cancel(t));
assert(!pthread_join(t, &ret));
assert(PTHREAD_CANCELED == ret);
return 0;
}
% make test CFLAGS='-Os -Wall -W -D_APPLE_C_SOURCE'
cc -Os -Wall -W -D_APPLE_C_SOURCE test.c -o test
% ./test
creating a thread with arg 0xbffffc7c
cleanup called with 0xbffffc7c
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden