I've noticed some unexpected behaviour with winpthreads which I believe is a bug. Thread-cancellation cleanup handlers are not called when a thread terminates due to a call to pthread_exit(). This is unexpected; the pthread_cleanup_push(), pthread_cleanup_pop() specification [1] mentions:
The cancellation cleanup handler shall be popped from the cancellation cleanup stack and invoked with the argument arg when: The thread exits (that is, calls pthread_exit()).
[1] http://pubs.opengroup.org/onlinepubs/000095399/functions/pthread_cleanup_pop.html
An example program illustrating winpthreads failing to invoke cleanup handlers follows:
void cleanup_func(void arg)
{
printf("cleanup_func()\n");
}
void func(void arg)
{
printf("func()\n");
pthread_cleanup_push(cleanup_func, 0);
pthread_exit(NULL);
pthread_cleanup_pop(1);
}
int main()
{
pthread_t t;
void *ret;
pthread_create(&t, NULL, func, (void*)NULL); pthread_join(t, &ret); return 0;
}