From: Ross Johnson <Ross.Johnson@homemail.com.au>
To: gmx <onsager@gmx.net>
Cc: pthreads-win32@sourceware.org
Subject: Re: Accessing Windows thread id
Date: Sun, 27 May 2007 07:30:00 -0000 [thread overview]
Message-ID: <46584240.7060108@homemail.com.au> (raw)
In-Reply-To: <1522450048.20070526151035@gmx.net>
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
next prev parent reply other threads:[~2007-05-26 14:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-26 14:21 Michael Bieber
2007-05-27 7:30 ` Ross Johnson [this message]
2007-05-27 9:07 ` Michael Bieber
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=46584240.7060108@homemail.com.au \
--to=ross.johnson@homemail.com.au \
--cc=onsager@gmx.net \
--cc=pthreads-win32@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).