From patchwork Wed Sep 26 15:00:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Hayward X-Patchwork-Id: 29552 Received: (qmail 127350 invoked by alias); 26 Sep 2018 15:01:00 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 127212 invoked by uid 89); 26 Sep 2018 15:00:54 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=Hayward, hayward, Hx-languages-length:1515 X-HELO: EUR04-HE1-obe.outbound.protection.outlook.com Received: from mail-eopbgr70058.outbound.protection.outlook.com (HELO EUR04-HE1-obe.outbound.protection.outlook.com) (40.107.7.58) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 26 Sep 2018 15:00:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=sC45fWhPcxLJA6149t6HweCJf314hilCZHYEHH/9yEo=; b=f0pvt59ycaRsR8sdXE/PEkNOghq5xBxN+MR65+gUZ0ulCUECuJvdGjBeWgHf/YQZ1YmMf6ZuYz6rgXlMbKWJSaPxiMgPyS6gqdWPXs9hv1UnPyCYBflI6EcWa7Jcu655fLK29msWzXFFjKgrbMLbhd0vueMLVV6pK08VrbpxL2M= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Alan.Hayward@arm.com; Received: from C02TF0U7HF1T.manchester.arm.com (217.140.106.32) by VI1PR0802MB2141.eurprd08.prod.outlook.com (2603:10a6:800:9b::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1164.22; Wed, 26 Sep 2018 15:00:41 +0000 From: Alan Hayward To: gdb-patches@sourceware.org Cc: nd@arm.com, Alan Hayward Subject: [PATCH] [testsuite][racy] Fix race condition in check-libthread-db Date: Wed, 26 Sep 2018 16:00:35 +0100 Message-Id: <20180926150035.96813-1-alan.hayward@arm.com> MIME-Version: 1.0 Return-Path: alan.hayward@arm.com Received-SPF: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-IsSubscribed: yes It is possible for the created thread to reach the breakpoint before the main thread has set errno to 23. Prevent this using a pthread barrier. gdb/testsuite/ChangeLog: 2018-09-26 Alan Hayward * gdb.threads/check-libthread-db.c (thread_routine): Use a pthread barrier. (main): Likewise. --- gdb/testsuite/gdb.threads/check-libthread-db.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gdb/testsuite/gdb.threads/check-libthread-db.c b/gdb/testsuite/gdb.threads/check-libthread-db.c index 85a97a93af..39d39694ce 100644 --- a/gdb/testsuite/gdb.threads/check-libthread-db.c +++ b/gdb/testsuite/gdb.threads/check-libthread-db.c @@ -23,6 +23,10 @@ #include #include +/* This barrier ensures we only reach the initial breakpoint both threads have + set errno. */ +pthread_barrier_t start_threads_barrier; + static void break_here (void) { @@ -32,6 +36,7 @@ static void * thread_routine (void *arg) { errno = 42; + pthread_barrier_wait (&start_threads_barrier); break_here (); @@ -47,6 +52,8 @@ main (int argc, char *argv) pthread_t the_thread; int err; + pthread_barrier_init (&start_threads_barrier, NULL, 2); + err = pthread_create (&the_thread, NULL, thread_routine, NULL); if (err != 0) { @@ -55,6 +62,7 @@ main (int argc, char *argv) } errno = 23; + pthread_barrier_wait (&start_threads_barrier); err = pthread_join (the_thread, NULL); if (err != 0)