Re: mutex PTHREAD_MUTEX_ERRORCHECK and pthread_cancel issues
site_archiver@lists.apple.com Delivered-To: Darwin-dev@lists.apple.com On May 12, 2005, at 11:25 AM, Stéphane Letz wrote: 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 (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... 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? This email sent to site_archiver@lists.apple.com
participants (1)
-
Matt Watson