From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7427 invoked by alias); 12 Jan 2008 01:32:24 -0000 Received: (qmail 7419 invoked by uid 22791); 12 Jan 2008 01:32:23 -0000 X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (65.74.133.4) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sat, 12 Jan 2008 01:32:02 +0000 Received: (qmail 14488 invoked from network); 12 Jan 2008 01:32:00 -0000 Received: from unknown (HELO localhost) (jimb@127.0.0.2) by mail.codesourcery.com with ESMTPA; 12 Jan 2008 01:32:00 -0000 To: gdb-patches@sourceware.org Subject: RFA: Make sigthread.exp more reliable From: Jim Blandy Date: Sat, 12 Jan 2008 01:32:00 -0000 Message-ID: User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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: 2008-01/txt/msg00300.txt.bz2 sigthread.exp fails intermittently, because the program exits due to a segfault instead of the ^C GDB sends it. I believe this is because the threads throwing signals at each other don't wait until all the pthread_t variables are initialized before they do so. So they occasionally pass an uninitialized pthread_t to pthread_kill, which segfaults. This patch uses barriers to make sure everyone's ready to go before the fun begins. Although barriers were not in the original POSIX threads spec, they have been in the GNU C library since version 2.2, released in 2000. When barriers are not present, the test reports itself as "UNSUPPORTED". Is this okay? gdb/testsuite/ChangeLog: 2008-01-11 Jim Blandy * gdb.threads/sigthread.c: Use barriers to ensure that child_thread and child_thread_two are always initialized before we start to use them. diff -r a4b196da8237 -r 15f7131243ac gdb/testsuite/gdb.threads/sigthread.c --- a/gdb/testsuite/gdb.threads/sigthread.c Fri Jan 11 14:54:31 2008 -0800 +++ b/gdb/testsuite/gdb.threads/sigthread.c Fri Jan 11 17:15:53 2008 -0800 @@ -20,6 +20,8 @@ testing. */ #define NSIGS 10000000 +pthread_barrier_t barrier; + void handler (int sig) { @@ -34,6 +36,8 @@ child_two (void *arg) { int i; + pthread_barrier_wait (&barrier); + for (i = 0; i < NSIGS; i++) pthread_kill (child_thread, SIGUSR1); } @@ -42,6 +46,8 @@ thread_function (void *arg) thread_function (void *arg) { int i; + + pthread_barrier_wait (&barrier); for (i = 0; i < NSIGS; i++) pthread_kill (child_thread_two, SIGUSR2); @@ -54,9 +60,13 @@ int main() signal (SIGUSR1, handler); signal (SIGUSR2, handler); + pthread_barrier_init (&barrier, NULL, 3); + main_thread = pthread_self (); pthread_create (&child_thread, NULL, thread_function, NULL); pthread_create (&child_thread_two, NULL, child_two, NULL); + + pthread_barrier_wait (&barrier); for (i = 0; i < NSIGS; i++) pthread_kill (child_thread_two, SIGUSR1);