From patchwork Fri Dec 5 18:52:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Torvald Riegel X-Patchwork-Id: 418276 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 273A0140100 for ; Sat, 6 Dec 2014 05:53:08 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:subject:from:to:in-reply-to:references :content-type:date:message-id:mime-version; q=dns; s=default; b= YI/dMj+f+mJTaIY7RBZ+JK7PONywOQhNzD2qfB6gzeKYyYIaoHmwC3i2VZS7JAZG E2X1Q7Ibh6y+ZnI/bCiUDKJGCuBACyD1frftIFmu5DXVeN7tyeB3gQ+7axVJ3vaC 4bqV44AemNhRxgOg9Ffy1OY/L08Ni3rV9cT4nnvrr8A= 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:subject:from:to:in-reply-to:references :content-type:date:message-id:mime-version; s=default; bh=68rC++ AwlXoK/xwIexA2nAnKwdg=; b=GCxSYOhiXcw2EpHlDfZaYeheN5w8boGIaUEP1R 0pE4UtJ7EbxAFPjdkOkVYg7zbQ65TkcL/FPdRg0yTBHmMtFc+oPkiXN6eUUADDk8 /b/yeTNuSBVMejg6fTfpOm+ZlaSaJBUnQCpIb11pKvv/YGXMc6lz7cnobzvd1GZi gQi24= Received: (qmail 24952 invoked by alias); 5 Dec 2014 18:53:03 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 24934 invoked by uid 89); 5 Dec 2014 18:53:02 -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: [PATCH 1/3] Use reliable sem_wait interruption in nptl/tst-sem6. From: Torvald Riegel To: GLIBC Devel In-Reply-To: <1417804668.22797.108.camel@triegel.csb> References: <1417804668.22797.108.camel@triegel.csb> Date: Fri, 05 Dec 2014 19:52:57 +0100 Message-ID: <1417805577.25868.4.camel@triegel.csb> Mime-Version: 1.0 This makes the nptl/tst-sem6 interrupt sem_wait reliably by letting the signal handler call sem_post. This ensures that if the signal handler should happen to run before sem_wait actually starts, sem_wait will find an available token and return. This is necessary if a program does not want to rely on timing nor on forward progress / fairness guarantees of the OS scheduler. It's needed so that Patch 3/3 can do the right thing in face of a FUTEX_WAIT that may return EINTR on either signal interruption or spuriously. commit a819010e2a625eafc66fb1bf1301fcba5c05e5e6 Author: Torvald Riegel Date: Thu Dec 4 20:43:22 2014 +0100 Use reliable sem_wait signal interruption in tst-sem6 diff --git a/nptl/tst-sem6.c b/nptl/tst-sem6.c index 2d9f1ab..3efd4eb 100644 --- a/nptl/tst-sem6.c +++ b/nptl/tst-sem6.c @@ -22,6 +22,7 @@ #include #include +sem_t s; static void handler (int sig) @@ -34,6 +35,10 @@ handler (int sig) sigaction (SIGALRM, &sa, NULL); + /* Correctly interrupting a sem_wait without relying on timing assumptions + requires using sem_post in the handler. */ + sem_post (&s); + /* Rearm the timer. */ alarm (1); } @@ -42,7 +47,6 @@ handler (int sig) static int do_test (void) { - sem_t s; struct sigaction sa; sa.sa_handler = handler; @@ -61,14 +65,12 @@ do_test (void) 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; }