From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6255 invoked by alias); 8 Dec 2014 11:43:25 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 6245 invoked by uid 89); 8 Dec 2014 11:43:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.0 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Subject: Re: [PATCH 1/3] Use reliable sem_wait interruption in nptl/tst-sem6. From: Torvald Riegel To: =?UTF-8?Q?Ond=C5=99ej_B=C3=ADlka?= Cc: GLIBC Devel In-Reply-To: <20141206135040.GA16212@domone> References: <1417804668.22797.108.camel@triegel.csb> <1417805577.25868.4.camel@triegel.csb> <20141206135040.GA16212@domone> Content-Type: text/plain; charset="UTF-8" Date: Mon, 08 Dec 2014 11:43:00 -0000 Message-ID: <1418038997.25868.34.camel@triegel.csb> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-SW-Source: 2014-12/txt/msg00187.txt.bz2 On Sat, 2014-12-06 at 14:50 +0100, Ondřej Bílka wrote: > On Fri, Dec 05, 2014 at 07:52:57PM +0100, Torvald Riegel wrote: > > alarm (1); > > > > int res = sem_wait (&s); > > - if (res == 0) > > - { > > - puts ("wait succeeded"); > > - return 1; > > - } > > - if (res != -1 || errno != EINTR) > > + /* We accept all allowed behavior: Implementations that return EINTR and > > + those that rely on correct interruption through signals to use sem_post > > + in the signal handler. */ > > + if (res != 0 && !(res == -1 && errno == EINTR)) > > { > > - puts ("wait didn't fail with EINTR"); > > + puts ("wait neiter succeeded nor failed with EINTR"); > > return 1; > > } > > > > That does change test logic as it originally failed when wait succeeded. Yes, but why do you think that this is inconsistent? The previous test didn't add a token in the signal handler, so if wait succeeded, then the test should fail. However, the correct way to interrupt the semaphore with a signal is to add a token. My patch does that. Second, if we do not want to make timing assumptions (which the existing test would do if we add a token to the semaphore in the signal handler), then we need to accept that the (first) signal handler execution might happen before sem_wait actually executes. Therefore, we must not fail in this case. We have to correctly interrupt with signals because as the futex documentation stands (allowing return of EINTR on spurious wake-ups), there's no way to implement the specific behavior of the existing implementation (which assumes EINTR is returned *only* on signals). IOW, the existing test does white-box testing with timing assumptions; with this patch, we do make a slightly different black-box test with no timing assumptions.