From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Kevin D. Clark" To: Pthreads Developers List Subject: Re: C++ cleanup handler execution Date: Fri, 14 Jan 2000 08:27:00 -0000 Message-id: <14463.20160.891089.94040@cabletron.com> References: <14453.4956.759854.712859@cabletron.com> <14463.19695.396800.542343@cabletron.com> X-SW-Source: 2000/msg00009.html Sorry, in my previous email my test file got garbled. My fault. --kevin Here's the test file: // this is a C++ program #ifdef __unix #include #else #endif #include #include "stdio.h" void *canceledRoutine(void *), *anotherRoutine(void *); pthread_t canceledThread, anotherThread; int main(int argc, char *argv[]) { int i = 0; pthread_attr_t tattr; pthread_attr_init(&tattr); pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED); for (i=0; i<10000; i++) { pthread_create(&canceledThread, &tattr, canceledRoutine, (void *)i); pthread_create(&anotherThread, 0, anotherRoutine, (void *)i); pthread_join(anotherThread, 0); } sleep(5); } void cancelCleanup(void *arg) { int i = (int)arg; fprintf(stderr, "%d -- Hey, I've been canceled!\n", i); } void * canceledRoutine(void *arg) { int i = (int)arg; pthread_cleanup_push(cancelCleanup, i); while(1) { // sleep() is defined to be a cancelation point sleep(1); } pthread_cleanup_pop(0); return 0; } void * anotherRoutine(void *arg) { int i = (int)arg; pthread_cancel(canceledThread); return 0; }