From owner-freebsd-hackers@FreeBSD.ORG Thu Jun 3 20:09:33 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 556A4106566B for ; Thu, 3 Jun 2010 20:09:33 +0000 (UTC) (envelope-from deischen@freebsd.org) Received: from mail.netplex.net (mail.netplex.net [204.213.176.10]) by mx1.freebsd.org (Postfix) with ESMTP id EB9438FC12 for ; Thu, 3 Jun 2010 20:09:32 +0000 (UTC) Received: from sea.ntplx.net (sea.ntplx.net [204.213.176.11]) by mail.netplex.net (8.14.4/8.14.4/NETPLEX) with ESMTP id o53K9Vv4011816; Thu, 3 Jun 2010 16:09:31 -0400 (EDT) X-Virus-Scanned: by AMaViS and Clam AntiVirus (mail.netplex.net) X-Greylist: Message whitelisted by DRAC access database, not delayed by milter-greylist-4.2.2 (mail.netplex.net [204.213.176.10]); Thu, 03 Jun 2010 16:09:31 -0400 (EDT) Date: Thu, 3 Jun 2010 16:09:31 -0400 (EDT) From: Daniel Eischen X-X-Sender: eischen@sea.ntplx.net To: =?UTF-8?B?VsOhY2xhdiBIYWlzbWFu?= In-Reply-To: <4C07FF45.5070703@sh.cvut.cz> Message-ID: References: <6e716c850fa84621482b71826dae55d5@shell.sh.cvut.cz> <4C07FF45.5070703@sh.cvut.cz> MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="-559023410-1804928587-1275595771=:29332" Cc: freebsd-hackers@freebsd.org Subject: Re: How to get a thread ID? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Daniel Eischen List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Jun 2010 20:09:33 -0000 This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. ---559023410-1804928587-1275595771=:29332 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE On Thu, 3 Jun 2010, V=C3=A1clav Haisman wrote: > Daniel Eischen wrote, On 3.6.2010 16:51: >> On Thu, 3 Jun 2010, V=C3=A1clav Haisman wrote: >> >>> >>> Hi, >>> is it possible to obtain some sort of a thread ID that identifies a thr= ead >>> within a process other than pthread_self()? Something like gettid() on >>> Linux? Apparently, on FreeBSD the pthread_t is a pointer type and does = not >>> identify the thread well enough. GDB on FreeBSD seems to know about thr= eads >>> and does not seem to use the same ID as is pthread_t. >> >> "identifies a thread" well enough for what? pthread_t is suppose >> to be opaque. Whether it is an int, pointer, or whatever, it is >> implementation-defined and not suppose provide any more information >> than available through the standard pthread interfaces. There are >> some non-portable interfaces in though. > Exactly, pthread_t is opaque and it thus it is only by a chance that I ca= n > print its value, it is a pointer on FreeBSD. It could as well be a struct= and > then I could not possibly do anything to print the thread identity on scr= een. > > * 4 Thread 28426ec0 (LWP 100172) 0x0804b9f6 in TestThread::run () > > As shown above, GDB can show some sort of ID, the LWP bit. How does it ge= t > it? Is it possible to get the LWP ID from inside the process without > debugging it? I think the value that it is showing (28426ec0) is the hex value of the pthread_t (pointer). You can also use pthread_[gs]etname_np() from if you want to associate an string identifier with a thread. --=20 DE ---559023410-1804928587-1275595771=:29332--