From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 90375 invoked by alias); 27 May 2015 12:23:26 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 90366 invoked by uid 89); 27 May 2015 12:23:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.1 required=5.0 tests=AWL,BAYES_50,KAM_LAZY_DOMAIN_SECURITY autolearn=no version=3.3.2 X-HELO: calimero.vinschen.de Received: from aquarius.hirmke.de (HELO calimero.vinschen.de) (217.91.18.234) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 27 May 2015 12:23:15 +0000 Received: by calimero.vinschen.de (Postfix, from userid 500) id A6792A807CE; Wed, 27 May 2015 14:23:12 +0200 (CEST) Date: Wed, 27 May 2015 12:39:00 -0000 From: Corinna Vinschen To: cygwin@cygwin.com Subject: Re: cygwin-2 process handling Message-ID: <20150527122312.GF16927@calimero.vinschen.de> Reply-To: cygwin@cygwin.com Mail-Followup-To: cygwin@cygwin.com References: <1573487218.1490468.1431969356192.JavaMail.yahoo@mail.yahoo.com> <555B6F71.4040906@cornell.edu> <555B7E03.40404@cornell.edu> <20150521205357.2c125b3bcaf877d0843b52b1@nifty.ne.jp> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="eNMatiwYGLtwo1cJ" Content-Disposition: inline In-Reply-To: <20150521205357.2c125b3bcaf877d0843b52b1@nifty.ne.jp> User-Agent: Mutt/1.5.23 (2014-03-12) X-SW-Source: 2015-05/txt/msg00345.txt.bz2 --eNMatiwYGLtwo1cJ Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-length: 2024 Hi Takashi, On May 21 20:53, Takashi Yano wrote: > [...] > I was looking into this problem, and found the PeekNamedPipe() > call is blocked in fhandler_pty_master::close() when the problem > occurs. >=20 > I had not noticed that,=20 >=20 > https://msdn.microsoft.com/en-us/library/windows/desktop/aa365779(v=3Dvs.= 85).aspx >=20 > says: > > The PeekNamedPipe function can block thread execution the same > > way any I/O function can when called on a synchronous handle in > > a multi-threaded application. >=20 > I have made a patch attached to resolve this problem. Please have > a look. >=20 > With this patch, NtQueryObject() is used instead of PeekNamedPipe() > to detect closure of the last master handle. >=20 > Please refer to the following discussion for more details. > http://cygwin.com/ml/cygwin/2015-03/msg00221.html >=20 >=20 > ChageLog is as follows. >=20 > 2015-05-21 Takashi Yano <...> >=20 > * fhandler_tty.cc (fhandler_pty_master::close): Use NtQueryObject() > instead of PeekNamedPipe() to detect closing the last master handle. > [...] > + if (output_handle_local) > + { > + OBJECT_BASIC_INFORMATION obi; > + NTSTATUS status; > + ULONG hdl_cnt =3D 0; > + > + status =3D NtQueryObject (output_handle_local, ObjectBasicInformat= ion, > + &obi, sizeof obi, NULL); > + if (!NT_SUCCESS (status)) > + debug_printf ("NtQueryObject: %y", status); > + else > + hdl_cnt =3D obi.HandleCount; > + termios_printf("HandleCount: %d", hdl_cnt); > + if (hdl_cnt =3D=3D 1) > + SetEvent (input_available_event); > + CloseHandle (output_handle_local); > + } =20 Isn't that racy? Consider two processes doing that at the same time. Both calls to NtQueryObject could come up with hdl_cnt =3D=3D 2 and the problem persists. Wouldn't it be safer to call SetEvent(input_available_event) all the time from here? Corinna --=20 Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Maintainer cygwin AT cygwin DOT com Red Hat --eNMatiwYGLtwo1cJ Content-Type: application/pgp-signature Content-length: 819 -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJVZbcwAAoJEPU2Bp2uRE+gb6YP/3AKtY7kYmlj0aVlmrV1odZv NpxE0B+KFXl0Nlv6e3lm62+XgETaQCI9HorA00cIDL8gewjcmEchXuZ6e5AaFCnR lHou77HUz/QrcsDthWetU/pTuoD5dVDYYaIlL9JqlMkqHmUkifuLoUyOZcnMjYdl HPJrqGlGpQQXlMtxCxDSmN8H1U7Jwu6XD2YygAt42zdiXYjd0hEl/P5xa9jid1rO KjQTy00MXtPh29XCb1pgUSqmyEdG9lBLFz+O+71+8uPXWqXAtLYpubsSM1XvtbhN tuj2to6lNM1YxZrP/WFpVpTfBfmkyIGRRVSIwNbL+7WQosuTYSpVkc8sqHTUGlDm vMDLYc2Wkudihz8mCBt9sPr2Zw05kFZeaj72h2ZHbqoEE3TyHX7mtIU4Tyq1euKu i1QbpelkkCfpMPpxvC0TVvYq92WX/fHgZ2WwhmaIFCd1tNucf7EULCfXq3WUtmyG Uq4iEWb2leTRPYYM5bEMwxuvW4cK89QYjbD9e5q7brH6/vcqHj2HNxov4T5y2A9i Rb2yVnTOz+3NrqslDZi99gZ9x4FWuw5u1Y48c2AoSXbL9M7IzJJRme1IL7/SuiAC 1piF8eC2HLGkCS6BuZtn+ytuThG1MTLRN5xqqxENwCMoBZ4CLvP1DtTZ9yLP/Wb3 NoVewy5Q3GwFgXMtK9W4 =JHk5 -----END PGP SIGNATURE----- --eNMatiwYGLtwo1cJ--