From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10419 invoked by alias); 26 May 2007 14:21:03 -0000 Received: (qmail 10410 invoked by uid 22791); 26 May 2007 14:21:02 -0000 X-Spam-Check-By: sourceware.org Received: from quokka.dot.net.au (HELO quokka.dot.net.au) (202.147.68.10) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sat, 26 May 2007 14:20:59 +0000 Received: from [203.129.44.110] (helo=[203.129.44.110]) by quokka.dot.net.au with esmtp (Exim 3.35 #1 (Debian)) id 1Hrx8S-0008Ad-00; Sun, 27 May 2007 00:20:48 +1000 Message-ID: <46584240.7060108@homemail.com.au> Date: Sun, 27 May 2007 07:30:00 -0000 From: Ross Johnson User-Agent: Thunderbird 1.5.0.10 (X11/20070302) MIME-Version: 1.0 To: gmx CC: pthreads-win32@sourceware.org Subject: Re: Accessing Windows thread id References: <1522450048.20070526151035@gmx.net> In-Reply-To: <1522450048.20070526151035@gmx.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact pthreads-win32-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: pthreads-win32-owner@sourceware.org X-SW-Source: 2007/txt/msg00027.txt.bz2 Michael Bieber wrote: > @list > > I would like exploit the technique, described here: > > http://msdn2.microsoft.com/en-us/library/xcb2z8hs(vs.80).aspx > > in order to help my Visual Studio debugger with some more expressive > thread names. > > Unfortunately, this is relying on a thread id not being public > accessible for pthreads_win32 clients (It is the last argument to > _beginthreadex, after that call hidden inside the non-public > ptw32_thread_t structure). Windows GetThreadId is no help here, because > it isn't defined for Win XP. Even GetCurrentId is not entirely what I > would like, because the call to SetThreadName (cf. URL above) doesn't > come from the calling thread in my case. > > So, is there a way to get the Windows thread id in a way similar to > pthread_getw32threadhandle_np for a handle? > Not nicely but otherwise, yes. As you've found, the win32 thread ID returned by the last arg of _beginthreadex() is stored at offset zero in the opaque pthw32_thread_t_ struct, which is pointed to by the first element (offset zero) of the pthread_t struct, a pointer to which is the first arg passed to pthread_create(). So the code below should get you close if not all the way there:- DWORD w32threadID; pthread_t tid; pthread_create(&tid, ...); w32threadID = (DWORD) ((void *)tid)[0][0]; I'll add another function to the library to return this nicely - called, say, pthread_getw32threadid_np(). Regards. Ross