pthread_cancel() does not work in Mac OS X
I wrote a simple sample program to illustrate that pthread_cancel() does not work on Mac OS X (checked on 10.2, 10.3 and 10.4). Does anyone know why is that and if it may be fixed?
Thanks!
Example program:
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
void CleanupFunc(void *p)
{
fprintf(stderr, "Cleanup\n");
}
void * AThreadFunc(void *p)
{
pthread cleanuppush(CleanupFunc, 0);
sleep(20);
pthread cleanuppop(1);
return 0;
}
int main()
{
pthread_t thr;
pthread_create(&thr, 0, AThreadFunc, 0);
sleep(2);
pthread_cancel(thr);
sleep(10);
return 0;
}
The program is meant to write string "Cleanup", which means that the cleanup function is called. Investigation showed that pthread_cancel() does not have any effect on the thread. At the same time this program works as expected on Linux and Solaris.
Thanks!
Example program:
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
void CleanupFunc(void *p)
{
fprintf(stderr, "Cleanup\n");
}
void * AThreadFunc(void *p)
{
pthread cleanuppush(CleanupFunc, 0);
sleep(20);
pthread cleanuppop(1);
return 0;
}
int main()
{
pthread_t thr;
pthread_create(&thr, 0, AThreadFunc, 0);
sleep(2);
pthread_cancel(thr);
sleep(10);
return 0;
}
The program is meant to write string "Cleanup", which means that the cleanup function is called. Investigation showed that pthread_cancel() does not have any effect on the thread. At the same time this program works as expected on Linux and Solaris.