From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id P6FlMbR8mGmg2wIAWB0awg (envelope-from ) for ; Fri, 20 Feb 2026 10:24:36 -0500 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=uG2TVYwm; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id AFBAF1E089; Fri, 20 Feb 2026 10:24:36 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 0E7F61E089 for ; Fri, 20 Feb 2026 10:24:35 -0500 (EST) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 833F44B9DB57 for ; Fri, 20 Feb 2026 15:24:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 833F44B9DB57 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=uG2TVYwm Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 298D14BA23FD for ; Fri, 20 Feb 2026 15:24:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 298D14BA23FD Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=polymtl.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=polymtl.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 298D14BA23FD Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=132.207.4.11 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1771601048; cv=none; b=pNpviWnEAg0G6uvVrzGpZacBhtCc1W3fLsrYpm7xpWn0Vt46k9Au5nLa/V/5tPftm6jyKnVqM5yNoFE5SbVX7DFUZws7fGFnAIR3pnFZPyh6SqoJ9Ce5Ffx67RrPdB5b+3n+mGFElO/4zsQ9dqrIeX0LgSm8K478IITlApgB2tk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1771601048; c=relaxed/simple; bh=gAC1Gpu75/a4DH/6vHdkp4SlWBav0txgCr6DFV3Sy6g=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=xnsjn8mS1CrUx0o/m99Hqc3anNsA71d6sVO+j/5MN9L0SGZQfXrzKvZ4MG3CSxF5NtSHPvC/PySPRSNIK86sa5Ml52SVYxdJg04Rw2Os2jJ1hx/K4/MksScksrDmIq88rG2I+WITRHkURbpMLDT2TSBv9EGgdqWVVvN1VOGqY2w= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 298D14BA23FD Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 61KFO2pu015877 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 20 Feb 2026 10:24:07 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 61KFO2pu015877 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=oct2025; t=1771601047; bh=Qqvu2N5jrRn71T+lr317A8MTt/nvZOl+6xlhIEiZSFs=; h=Date:Subject:To:From:In-Reply-To:From; b=uG2TVYwmiwgmeubeVCJHXJq3nHNNtVn281gU9J7C015Ln964RXxVh1qjmkzAzZ6fE gvQ9wfHyMGkF7OYpClawFG4AHJvRgl9RusdskBmqnqJQROu0v7zrahX6fLoaPXdq6h Y4q7iUijh1skZK4W2RX8ZjwORkFFmMWK+hSLCwYtqtV0/AgC4duSZ/Qjrp++G6r59V 4SUoRE/YOems9buj7QYBYdeICgI7DUKn8j3RFOmJzyT57aEbdSeKpDMRIvV5Ud6sET u8wFLxgDUOqfvhxT6dqZXHLeb8E+ruLuKDHdw6Tun18A+wUn8IQ/f8Ef6g8GOWnWAF ZSSk3Hafi8wzA== Received: by simark.ca (Postfix) id 5AF381E089 for ; Fri, 20 Feb 2026 10:24:01 -0500 (EST) Message-ID: Date: Fri, 20 Feb 2026 10:24:01 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] gdb/testsuite: fix race condition in gdb.replay/missing-thread.c To: gdb-patches@sourceware.org References: <20260206175807.631814-1-simon.marchi@polymtl.ca> Content-Language: fr From: Simon Marchi In-Reply-To: <20260206175807.631814-1-simon.marchi@polymtl.ca> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Fri, 20 Feb 2026 15:24:02 +0000 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org Ping. On 2/6/26 12:57 PM, simon.marchi@polymtl.ca wrote: > From: Simon Marchi > > I get frequent failures in gdb.replay/missing-thread.exp, starting with: > > FAIL: gdb.replay/missing-thread.exp: non_stop=on: record_initial_logfile: continue (timeout) > > I tracked this down to a race condition in the test program, causing it > not to generate the expected SIGTRAP. This can be reproduced by adding > a sleep(1) just after the pthread_create. > > The expected behavior is: > > - The main thread starts a second thread > - The main thread blocks on pthread_cond_wait, waiting to be notified > by the second thread (to make sure the second thread had time to > start) > - The second thread notifies the main thread using pthread_cond_signal > - The main thread sends a SIGTRAP to the second thread > > However, this can happen: > > - The main thread starts a second thread > - The second thread calls pthread_cond_signal, while no one is waiting > to the condvar > - The main thread blocks on pthread_cond_wait forever > > Fix it by introducing a separate boolean predicate protected by the > shared mutex, and looping until it is true. This is the way > pthread_cond_wait is meant to be used. From pthread_cond_wait(3): > > When using condition variables there is always a boolean predicate > involving shared variables associated with each condition wait that > is true if the thread should proceed. Spurious wakeups from the > pthread_cond_wait() or pthread_cond_timedwait() functions may occur. > Since the return from pthread_cond_wait() or > pthread_cond_timedwait() does not imply anything about the value of > this predicate, the predicate should be re-evaluated upon such > return. > > Finally, make things static, just out of principle, and fix minor > formatting issues. > > Change-Id: I62ba2085a2d506dc3d91e32cd5de48c43a3ff55e > --- > gdb/testsuite/gdb.replay/missing-thread.c | 18 ++++++++++++------ > 1 file changed, 12 insertions(+), 6 deletions(-) > > diff --git a/gdb/testsuite/gdb.replay/missing-thread.c b/gdb/testsuite/gdb.replay/missing-thread.c > index 0a17be1c7dd1..aad6396f24c2 100644 > --- a/gdb/testsuite/gdb.replay/missing-thread.c > +++ b/gdb/testsuite/gdb.replay/missing-thread.c > @@ -22,23 +22,28 @@ > #include > #include > > -pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER; > -pthread_cond_t g_condvar = PTHREAD_COND_INITIALIZER; > +static pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER; > +static pthread_cond_t g_condvar = PTHREAD_COND_INITIALIZER; > +static bool g_ready = false; > > -void * > +static void * > worker_function (void *arg) > { > printf ("In worker, about to notify\n"); > + > + pthread_mutex_lock (&g_mutex); > + g_ready = true; > + pthread_mutex_unlock (&g_mutex); > pthread_cond_signal (&g_condvar); > > while (true) > - sleep(1); > + sleep (1); > > return NULL; > } > > int > -main() > +main () > { > pthread_t my_thread; > > @@ -46,7 +51,8 @@ main() > assert (result == 0); > > pthread_mutex_lock (&g_mutex); > - pthread_cond_wait (&g_condvar, &g_mutex); > + while (!g_ready) > + pthread_cond_wait (&g_condvar, &g_mutex); > > printf ("In main, have been woken.\n"); > pthread_mutex_unlock (&g_mutex); > > base-commit: deb47060b5812c6c41ecc790cb28898fcbc45c93 > -- > 2.53.0 >