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()).

An example program illustrating winpthreads failing to invoke cleanup 
handlers follows:


#include <pthread.h>
#include <stdio.h>

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;
}



Thanks

Keri

[1] 
http://pubs.opengroup.org/onlinepubs/000095399/functions/pthread_cleanup_pop.html


------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to