X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SARE_MSGID_LONG45,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org MIME-Version: 1.0 In-Reply-To: <4BC42923.6000504@martoneradiotech.com> References: <4BC42923 DOT 6000504 AT martoneradiotech DOT com> Date: Tue, 13 Apr 2010 10:40:39 +0200 Received: by 10.213.2.79 with SMTP id 15mr3121028ebi.59.1271148039713; Tue, 13 Apr 2010 01:40:39 -0700 (PDT) Message-ID: Subject: Re: Cygwin v1.7.5: Destructor NOT Invoked In Threads Upon Thread Cancellation (Windows XP SP 3) From: Csaba Raduly To: cygwin AT cygwin DOT com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com On Tue, Apr 13, 2010 at 10:19 AM, Ken wrote: > Under Fedora Core 6 (Linux), compiling and executing the attached test > code with: > =A0"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: > =A0"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 > #include > #include > #include > > using namespace std; > > class coo{ > public: > =A0 =A0 =A0 =A0coo(){ > =A0 =A0 =A0 =A0cout<<"constructor"< =A0} > =A0~coo(){ > =A0 =A0 =A0 =A0cout<<"destructor"< =A0} > }; > > void *foo(bool *pntr){ > =A0 =A0 =A0 =A0coo instance; > > =A0// Indefinite sleep. > =A0while (*pntr){ > =A0 =A0sleep(1); > =A0} > > =A0 =A0 =A0 =A0return NULL; > } > > int main(){ > =A0 =A0 =A0 =A0bool boo =3D false; > =A0// Constructor/Destructor Test. > =A0{ > =A0 =A0foo(&boo); > =A0} > > =A0// Thread test. > =A0pthread_t thread; > =A0boo =3D true; > =A0pthread_create(&thread, NULL, (void *(*)(void*))(foo), &boo); > =A0sleep(1); > =A0pthread_cancel(thread); > =A0pthread_join(thread, NULL); > > =A0return 0; > } On Linux, the call stack at the second call to the destructor is: #0 ~coo (this=3D0x41dd10ff) at td.cc:14 #1 0x0000000000400b1b in foo (pntr=3D0x7ffff4705fff) 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 --=20 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