From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16697 invoked by alias); 30 Nov 2011 23:16:36 -0000 Received: (qmail 16689 invoked by uid 22791); 30 Nov 2011 23:16:35 -0000 X-SWARE-Spam-Status: No, hits=-7.4 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,SPF_HELO_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; Wed, 30 Nov 2011 23:16:20 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id pAUNGKfw024617 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 30 Nov 2011 18:16:20 -0500 Received: from mesquite.lan (ovpn-113-28.phx2.redhat.com [10.3.113.28]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id pAUNGJUK013923 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO) for ; Wed, 30 Nov 2011 18:16:20 -0500 Date: Wed, 30 Nov 2011 23:16:00 -0000 From: Kevin Buettner To: rda@sources.redhat.com Subject: [commit] Detect and allow thread id reuse Message-ID: <20111130161619.72f545ea@mesquite.lan> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact rda-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: rda-owner@sourceware.org X-SW-Source: 2011-q4/txt/msg00000.txt.bz2 I've committed the patch below. In a program which rapidly creates threads which in turn rapidly exit, it is possible for NPTL to reuse a recently exited thread id for a newly created thread. RDA can fail to detect this thread reuse. One particularly bad consequence is that RDA will fail to the new thread. The patch below allows for thread id reuse by comparing the lwp ids. While this will work well for NPTL, it might possibly not work for other thread implementations. Note that the TID_MAY_BE_REUSED should be moved into the configury at some point to accommodate other threading implementations. Kevin 2011-11-30 Kevin Buettner * thread-db.c (TID_MAY_BE_REUSED): Define. (find_new_threads_callback): Detect thread id reuse. Index: thread-db.c =================================================================== RCS file: /cvs/src/src/rda/unix/thread-db.c,v retrieving revision 1.20 diff -u -p -r1.20 thread-db.c --- thread-db.c 1 Dec 2009 00:27:09 -0000 1.20 +++ thread-db.c 30 Nov 2011 23:05:49 -0000 @@ -49,6 +49,7 @@ int thread_db_noisy = 0; #define ALWAYS_UPDATE_THREAD_LIST 0 +#define TID_MAY_BE_REUSED 1 /* * A tiny local symbol table. @@ -1426,11 +1427,25 @@ find_new_threads_callback (const td_thrh /* Enter the thread into a local list (unless it is TD_THR_UNKNOWN, which means its defunct). */ - if ((thread = thread_list_lookup_by_tid (ti.ti_tid)) == NULL) + if ((thread = thread_list_lookup_by_tid (ti.ti_tid)) == NULL +#if TID_MAY_BE_REUSED + || thread->ti.ti_lid != ti.ti_lid +#endif + ) { if (ti.ti_state != TD_THR_UNKNOWN) { - thread = add_thread_to_list (&ti); + if (thread) + { + /* Thread is being reused. What has happened here is that + one thread has died and another was created using the + same thread identifier. */ + if (thread_db_noisy) + fprintf (stderr, "(thread deletion / reuse: %s)\n", thread_debug_name (thread)); + thread->ti = ti; + } + else + thread = add_thread_to_list (&ti); if (thread_db_noisy) fprintf (stderr, "(new thread %s)\n", thread_debug_name (thread));