X-Recipient: archive-cygwin AT delorie DOT com DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:reply-to :references:mime-version:content-type:in-reply-to; q=dns; s= default; b=MlVUjK12XA+zUqgC1mvP9/kgNjYw0sZrDA4kZ9RoB3ke0YOr4idju lgJr9/kOWMVMRsToJhniWp2hrdhXnqng5j+sar0scg6tr/eRaeBu7xonU/U/DNJ9 3xX2eXK9miiZ4oOVfSFpQ0aZvExleg9Zd7vffKbET7y6rU7kkGt7UY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:reply-to :references:mime-version:content-type:in-reply-to; s=default; bh=77IEWOEwyq6DeA3PY2ChIKTghHU=; b=bk3E3d5XkvK2x/MdfCR27nElqd7F JqPKa4+ZqfbVEannRFFcMIK930rjbaJL2pZEQAgHAnYSaf5XXuMMClsj2vQV2tqV r6IPwoJQQFVZ2w6OUELoz1OPoHjbk9Z76pZKei1SvHXF4E63Fld+wzsg1DizavPc bKzDGWVlOyE8HM4= Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: 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 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-5.9 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.3.2 X-HELO: calimero.vinschen.de Date: Mon, 23 Feb 2015 13:59:14 +0100 From: Corinna Vinschen To: cygwin AT cygwin DOT com Subject: Re: Unexpected EINVAL from pthread_join Message-ID: <20150223125914.GO437@calimero.vinschen.de> Reply-To: cygwin AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com References: <20150222225437 DOT 271e929b AT tukaani DOT org> <20150223121445 DOT GL437 AT calimero DOT vinschen DOT de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="7gLe/sNPhR777EPF" Content-Disposition: inline In-Reply-To: <20150223121445.GL437@calimero.vinschen.de> User-Agent: Mutt/1.5.23 (2014-03-12) --7gLe/sNPhR777EPF Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Feb 23 13:14, Corinna Vinschen wrote: > On Feb 22 22:54, Lasse Collin wrote: > > It seems that a signal can cause pthread_join to incorrectly return > > EINVAL. I debugged it only a little but hopefully someone finds this > > useful: > >=20 > > In the file thread.cc, function pthread::join, the call to cygwait may > > return WAIT_SIGNALED if a signal is sent to the process. The switch > > statement handling the return value assumes that only WAIT_OBJECT_0 and > > WAIT_CANCELED are possible. The default section of the switch statement > > has a comment "should never happen" and it returns EINVAL. It might be > > that the problem occurs only when SA_RESTART isn't used. >=20 > Lasse, I'm sorry, but I can't handle that quickly. Since you're > looking into the code and apparently understanding it, maybe you'd > like to provide patches, too? Please have a look at > https://cygwin.com/contrib.html. Patches <=3D 10 lines don't even > need a copyright assignment. Having said that... I looked into the Linux man page for pthread_join(1). It doesn't mention signals and EINTR at all. Then I looked into the SUSv4 pages(2) and it only has this to say: The pthread_join() function shall not return an error code of [EINTR]. Searching further on this I found this(3): The wait in pthread_join is not broken by a signal. If a thread waiting in pthread_join receives a signal that is not masked, if will execute the signal handler, and then return to waiting in pthread_join. Taking that at face value, the following patch should do the right thing, doesn't it? Index: thread.cc =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/winsup/cygwin/thread.cc,v retrieving revision 1.296 diff -u -p -r1.296 thread.cc --- thread.cc 28 Nov 2014 20:46:13 -0000 1.296 +++ thread.cc 23 Feb 2015 12:58:59 -0000 @@ -2399,6 +2399,7 @@ pthread::join (pthread_t *thread, void * (*thread)->attr.joinable =3D PTHREAD_CREATE_DETACHED; (*thread)->mutex.unlock (); =20 +restart_on_signal: switch (cygwait ((*thread)->win32_obj_id, cw_infinite, cw_sig | cw_c= ancel)) { case WAIT_OBJECT_0: @@ -2413,6 +2414,9 @@ pthread::join (pthread_t *thread, void * joiner->cancel_self (); // never reached break; + case WAIT_SIGNALED: + debug_printf ("Signal received, restart"); + goto restart_on_signal; default: // should never happen return EINVAL; Corinna (1) http://linux.die.net/man/3/pthread_join (2) http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_join.= html (3) http://osr600doc.sco.com/man/html.PTHREAD/pthread_join.PTHREAD.html --=20 Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Maintainer cygwin AT cygwin DOT com Red Hat --7gLe/sNPhR777EPF Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBAgAGBQJU6yQiAAoJEPU2Bp2uRE+gMgIP/j5abRFr+2Zm/jx9jQXCJdWe kxWLm4D+4oGdvf66ZI1/BdmH1IL0/kb5BZ6ml6h+TrlHpQ0IwyDWuoVaEFEVmocb o1IuaPOWyefQ7haL+LdVUPUbZOqEwzxbyFWe0H6rLsmilA78lJxJfz7pCuMit/YE Lm9bJdXxNmgLWwTJH/eJCcC//3r4J3wfv62dWrWG+zqaqNsZ5VX/B2e1KUAhudIe tbfDjeK1lgEDEYW910FlxDCQUFKEnxu+NEfwCyTIsltoogS85COKHXw7/1mXLpqi VtfX4Av9JvRuuxiXfCGQn7FWcOE9mbd0575yJDBcbaunjwZNPtiImUuecAYj6+E1 aVDRc20P72vUp0bGkvEy6cLXFpyJeYVNhupclOR2UBkki80pM8kC6x8aWlA0ImT2 XxTC0RCZZ7qUZ2kXc0PWsawf2Yj0RanfnzXP+7Is9A05s7i6jq3bdbBTLXwTR7H7 6is9YvCG0FJAPkYaJPl7lwhU8D3fkwuWjtSaKOqqtmxqLR0uqukKEBkRMAQuW7W9 9CqwWLdYAEk86U74spZDian78fievnktv5rnBlJikJM/FdYLnKZp0RKYzp/x6ZRI i4wz1JwGZZDw5ZuMXXN/qWcF0dN9o4auwyS3/lJQRz+Vcdr2RaRa2BiS7mp/BVTJ uIJ5W/1DZmAZ44syH9LK =AmgR -----END PGP SIGNATURE----- --7gLe/sNPhR777EPF--