Re: [Mingw-w64-public] winpthreads cleanup handlers not called afterpthread_exit()

2015-03-21 Thread Keri Harris
On 21/03/2015 12:39, Victor Bombi wrote:
> May be it has some relation with?
>
> http://sourceforge.net/p/mingw-w64/mailman/message/31749147/

I don't think it's related; this has to do with explicit calls to 
thread_exit() not invoking cleanup handlers that were registered via 
pthread_cleanup_push().

Looking at the definition for pthread_cleanup_push() in 
winpthreads/include/pthread.h, it looks like the cleanup stack is only 
accessible via a local variable, and no mechanism exists to call these 
handlers unless pthread_cleanup_pop() is explicitly called. 
pthreads-win32 uses __try/__finally (for SEH) or 
pthread_setspecific()/pthread_getspecific() (for C cleanup) to ensure 
they're always called.


> - Original Message -
> From: "Keri Harris" 
> To: 
> Sent: Thursday, March 19, 2015 3:27 PM
> Subject: [Mingw-w64-public] winpthreads cleanup handlers not called
> afterpthread_exit()
>
>
>> 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 
>> #include 
>>
>> 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/95399/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
>
> --
> 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
>


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


[Mingw-w64-public] winpthreads cleanup handlers not called after pthread_exit()

2015-03-19 Thread Keri Harris
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 
#include 

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/95399/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