delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2010/04/13/04:41:09

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
Message-ID: <n2h1ef5a52f1004130140l4e1e25acmfb19e94ed73ed268@mail.gmail.com>
Subject: Re: Cygwin v1.7.5: Destructor NOT Invoked In Threads Upon Thread Cancellation (Windows XP SP 3)
From: Csaba Raduly <rcsaba AT gmail DOT com>
To: cygwin AT cygwin DOT com
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
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 <iostream>
> #include <errno.h>
> #include <pthread.h>
> #include <stdlib.h>
>
> using namespace std;
>
> class coo{
> public:
> =A0 =A0 =A0 =A0coo(){
> =A0 =A0 =A0 =A0cout<<"constructor"<<endl;
> =A0}
> =A0~coo(){
> =A0 =A0 =A0 =A0cout<<"destructor"<<endl;
> =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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019