From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15515 invoked by alias); 17 Dec 2009 19:50:37 -0000 Received: (qmail 15504 invoked by uid 22791); 17 Dec 2009 19:50:36 -0000 X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 17 Dec 2009 19:50:31 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nBHJoT7I001394 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 17 Dec 2009 14:50:29 -0500 Received: from host0.dyn.jankratochvil.net (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nBHJoRTr014731 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 17 Dec 2009 14:50:29 -0500 Received: from host0.dyn.jankratochvil.net (localhost [127.0.0.1]) by host0.dyn.jankratochvil.net (8.14.3/8.14.3) with ESMTP id nBHJoQd5021619 for ; Thu, 17 Dec 2009 20:50:26 +0100 Received: (from jkratoch@localhost) by host0.dyn.jankratochvil.net (8.14.3/8.14.3/Submit) id nBHJoQBL021618 for gdb-patches@sourceware.org; Thu, 17 Dec 2009 20:50:26 +0100 Date: Thu, 17 Dec 2009 19:50:00 -0000 From: Jan Kratochvil To: gdb-patches@sourceware.org Subject: [patch] testsuite: Fix a race by me - watchthreads-reorder.exp Message-ID: <20091217195026.GA21468@host0.dyn.jankratochvil.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-08-17) X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-12/txt/msg00234.txt.bz2 Hi, there is a bug explainable by man pthread_cond_signal: The [...] pthread_cond_signal() functions shall have no effect if there are no threads currently blocked on cond. meaning a race for the testcase. +FAIL: gdb.threads/watchthreads-reorder.exp: reorder1: continue a (timeout) One can reproduce the race on CVS HEAD by: # --- a/gdb/testsuite/gdb.threads/watchthreads-reorder.c # +++ b/gdb/testsuite/gdb.threads/watchthreads-reorder.c # @@ -89,6 +89,7 @@ thread1_func (void *unused) # int i; # volatile int rwatch_store; # # +sleep(1); # thread1_tid = gettid (); # i = pthread_cond_signal (&thread1_tid_cond); # assert (i == 0); # @@ -317,6 +318,7 @@ main (int argc, char **argv) # # if (thread1_tid == 0) # { # +sleep(2); # i = pthread_cond_wait (&thread1_tid_cond, &thread1_tid_mutex); # assert (i == 0); # Fixed; gdbstop_mutex got removed as it became redundant there. Going to check it in as obvious in several days (code is by me + it is just a testcase). Sorry, Jan gdb/testsuite/ 2009-12-17 Jan Kratochvil * gdb.threads/watchthreads-reorder.c (gdbstop_mutex): Remove. (thread1_func): Protect thread1_tid_cond by thread1_tid_mutex. Remove gdbstop_mutex handling. (thread2_func): Protect thread2_tid_cond by thread2_tid_mutex. Remove gdbstop_mutex handling. (main): Move thread1_tid_mutex and thread2_tid_mutex locks before pthread_create. Remove gdbstop_mutex handling. New comment. Remove pthread_cond_wait conditionalizations. --- a/gdb/testsuite/gdb.threads/watchthreads-reorder.c +++ b/gdb/testsuite/gdb.threads/watchthreads-reorder.c @@ -34,8 +34,6 @@ otherwise. */ #define TIMEOUT (gettid () == getpid() ? 10 : 15) -static pthread_mutex_t gdbstop_mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP; - static pid_t thread1_tid; static pthread_cond_t thread1_tid_cond = PTHREAD_COND_INITIALIZER; static pthread_mutex_t thread1_tid_mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP; @@ -90,12 +88,11 @@ thread1_func (void *unused) volatile int rwatch_store; thread1_tid = gettid (); + + timed_mutex_lock (&thread1_tid_mutex); i = pthread_cond_signal (&thread1_tid_cond); assert (i == 0); - - /* Be sure GDB is already stopped before continuing. */ - timed_mutex_lock (&gdbstop_mutex); - i = pthread_mutex_unlock (&gdbstop_mutex); + i = pthread_mutex_unlock (&thread1_tid_mutex); assert (i == 0); rwatch_store = thread1_rwatch; @@ -115,12 +112,11 @@ thread2_func (void *unused) volatile int rwatch_store; thread2_tid = gettid (); + + timed_mutex_lock (&thread2_tid_mutex); i = pthread_cond_signal (&thread2_tid_cond); assert (i == 0); - - /* Be sure GDB is already stopped before continuing. */ - timed_mutex_lock (&gdbstop_mutex); - i = pthread_mutex_unlock (&gdbstop_mutex); + i = pthread_mutex_unlock (&thread2_tid_mutex); assert (i == 0); rwatch_store = thread2_rwatch; @@ -267,7 +263,8 @@ main (int argc, char **argv) setbuf (stdout, NULL); - timed_mutex_lock (&gdbstop_mutex); + timed_mutex_lock (&thread1_tid_mutex); + timed_mutex_lock (&thread2_tid_mutex); timed_mutex_lock (&terminate_mutex); @@ -306,30 +303,21 @@ main (int argc, char **argv) state_wait (tracer, "T (stopped)"); } - timed_mutex_lock (&thread1_tid_mutex); - timed_mutex_lock (&thread2_tid_mutex); - - /* Let the threads start. */ - i = pthread_mutex_unlock (&gdbstop_mutex); - assert (i == 0); + /* Threads are now waiting at timed_mutex_lock (thread1_tid_mutex) and so + they could not trigger the watchpoints before GDB gets unstopped later. + Threads get resumed at pthread_cond_wait below. */ printf ("Waiting till the threads initialize their TIDs.\n"); - if (thread1_tid == 0) - { - i = pthread_cond_wait (&thread1_tid_cond, &thread1_tid_mutex); - assert (i == 0); + i = pthread_cond_wait (&thread1_tid_cond, &thread1_tid_mutex); + assert (i == 0); - assert (thread1_tid > 0); - } + assert (thread1_tid > 0); - if (thread2_tid == 0) - { - i = pthread_cond_wait (&thread2_tid_cond, &thread2_tid_mutex); - assert (i == 0); + i = pthread_cond_wait (&thread2_tid_cond, &thread2_tid_mutex); + assert (i == 0); - assert (thread2_tid > 0); - } + assert (thread2_tid > 0); printf ("Thread 1 TID = %lu, thread 2 TID = %lu, PID = %lu.\n", (unsigned long) thread1_tid, (unsigned long) thread2_tid,