This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Cygwin v1.7.5: Destructor NOT Invoked In Threads Upon Thread Cancellation (Windows XP SP 3)


On Tue, Apr 13, 2010 at 10:19 AM, Ken  wrote:
> Under Fedora Core 6 (Linux), compiling and executing the attached test
> code with:
> ?"g++ test.cpp -lpthread; ./a.out"
> produces the following expected output:
>
> OUTPUT (Fedora Core 6):
> -----------------------
> constructor
> destructor
> constructor
> destructor
>
> However, under Cygwin v1.7.5, compiling and executing the attached test
> code with
> the same exact command produces the following unexpected output:
>
> OUTPUT (Cygwin v1.7.5):
> -----------------------
> constructor
> destructor
> constructor
>
> As per POSIX spec from the following link:
> ?"http://www.opengroup.org/onlinepubs/009695399/";
>
> The description for the "pthread_cancel()" method is:
(snip)
>
> Cygwin Configuration Diagnostics
(snip 85 pages of text)

PCYMTATFWCDA: Please Configure Your Mailer To Attach Text Files With
Content-Disposition: Attachment

(Gmail respects Content-Disposition: inline and displays it as a
single humongous wall of text)

http://blog.crox.net/archives/23-How-to-set-thunderbird-to-correctly-attach-text-files-with-Content-Disposition-attachment-instead-of-inline.html


> #include <iostream>
> #include <errno.h>
> #include <pthread.h>
> #include <stdlib.h>
>
> using namespace std;
>
> class coo{
> public:
> ? ? ? ?coo(){
> ? ? ? ?cout<<"constructor"<<endl;
> ?}
> ?~coo(){
> ? ? ? ?cout<<"destructor"<<endl;
> ?}
> };
>
> void *foo(bool *pntr){
> ? ? ? ?coo instance;
>
> ?// Indefinite sleep.
> ?while (*pntr){
> ? ?sleep(1);
> ?}
>
> ? ? ? ?return NULL;
> }
>
> int main(){
> ? ? ? ?bool boo = false;
> ?// Constructor/Destructor Test.
> ?{
> ? ?foo(&boo);
> ?}
>
> ?// Thread test.
> ?pthread_t thread;
> ?boo = true;
> ?pthread_create(&thread, NULL, (void *(*)(void*))(foo), &boo);
> ?sleep(1);
> ?pthread_cancel(thread);
> ?pthread_join(thread, NULL);
>
> ?return 0;
> }

On Linux, the call stack at the second call to the destructor is:

#0  ~coo (this=0x41dd10ff) at td.cc:14
#1  0x0000000000400b1b in foo (pntr=0x7ffff4705fff) at td.cc:26
#2  0x00007f8cec2d43ea in start_thread () from /lib/libpthread.so.0
#3  0x00007f8ceb897cbd in clone () from /lib/libc.so.6
#4  0x0000000000000000 in ?? ()

This does not happen on Cygwin (breakpoint hit only once)

I wonder if this thread is related ?
http://sourceware.org/ml/cygwin/2010-02/msg00004.html




-- 
Life is complex, with real and imaginary parts

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]