From patchwork Fri Feb 17 20:38:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 65197 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BE9F6384F036 for ; Fri, 17 Feb 2023 20:38:54 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail.baldwin.cx (bigwig.baldwin.cx [66.216.25.90]) by sourceware.org (Postfix) with ESMTPS id E6ABA385B51D for ; Fri, 17 Feb 2023 20:38:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E6ABA385B51D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=FreeBSD.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=FreeBSD.org Received: from gimli.baldwin.net (c-98-35-126-114.hsd1.ca.comcast.net [98.35.126.114]) by mail.baldwin.cx (Postfix) with ESMTPSA id 5C3EE1A84C72 for ; Fri, 17 Feb 2023 15:38:26 -0500 (EST) From: John Baldwin To: gdb-patches@sourceware.org Subject: [PATCH 4/5] gdb.threads/next-bp-other-thread.c: Ensure child thread is started. Date: Fri, 17 Feb 2023 12:38:17 -0800 Message-Id: <20230217203818.11287-5-jhb@FreeBSD.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230217203818.11287-1-jhb@FreeBSD.org> References: <20230217203818.11287-1-jhb@FreeBSD.org> MIME-Version: 1.0 X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.6.4 (mail.baldwin.cx [0.0.0.0]); Fri, 17 Feb 2023 15:38:26 -0500 (EST) X-Virus-Scanned: clamav-milter 0.103.1 at mail.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_STATUS, KHOP_HELO_FCRDNS, SPF_HELO_PASS, SPF_SOFTFAIL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Use a pthread_barrier to ensure the child thread is started before the main thread gets to the first breakpoint. --- gdb/testsuite/gdb.threads/next-bp-other-thread.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gdb/testsuite/gdb.threads/next-bp-other-thread.c b/gdb/testsuite/gdb.threads/next-bp-other-thread.c index 60aa029464c..33c6ec11982 100644 --- a/gdb/testsuite/gdb.threads/next-bp-other-thread.c +++ b/gdb/testsuite/gdb.threads/next-bp-other-thread.c @@ -22,9 +22,13 @@ /* Always zero, used in breakpoint condition. */ volatile int global_zero; +static pthread_barrier_t threads_started_barrier; + void * child_function (void *arg) { + pthread_barrier_wait (&threads_started_barrier); + while (1) { usleep (1); /* set breakpoint child here */ @@ -39,7 +43,12 @@ main (void) pthread_t child_thread; int res; + pthread_barrier_init (&threads_started_barrier, NULL, 2); + res = pthread_create (&child_thread, NULL, child_function, NULL); + + pthread_barrier_wait (&threads_started_barrier); + sleep (2); /* set wait-thread breakpoint here */ exit (EXIT_SUCCESS); }