public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
* Accessing  Windows thread id
@ 2007-05-26 14:21 Michael Bieber
  2007-05-27  7:30 ` Ross Johnson
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Bieber @ 2007-05-26 14:21 UTC (permalink / raw)
  To: pthreads-win32

@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?

Micha

-- 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Accessing  Windows thread id
  2007-05-26 14:21 Accessing Windows thread id Michael Bieber
@ 2007-05-27  7:30 ` Ross Johnson
  2007-05-27  9:07   ` Michael Bieber
  0 siblings, 1 reply; 3+ messages in thread
From: Ross Johnson @ 2007-05-27  7:30 UTC (permalink / raw)
  To: gmx; +Cc: pthreads-win32

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Accessing  Windows thread id
  2007-05-27  7:30 ` Ross Johnson
@ 2007-05-27  9:07   ` Michael Bieber
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Bieber @ 2007-05-27  9:07 UTC (permalink / raw)
  To: pthreads-win32

RJ> I'll add another function to the library to return this nicely - called,
RJ> say, pthread_getw32threadid_np().

Hallo Ross,

I was able to circumvent my particular problem, but the new function
should be helpful for some other cases too.

Thank you,
Micha

p.s. The library did a great job during a Linux->Windows port of 100
kLOC, saving a *lot* of time here. Additionally, it is very helpful in
maintaining a common source tree for both OS variants of our software.
Keep up the good work and thank you again!

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-05-27  7:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-26 14:21 Accessing Windows thread id Michael Bieber
2007-05-27  7:30 ` Ross Johnson
2007-05-27  9:07   ` Michael Bieber

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).