For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > June 2007 > Re: How to print out thread id from pthread_t









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: How to print out thread id from pthread_t
David Schwartz

2007-06-25, 7:13 pm

On Jun 18, 8:44 am, Herman.Schu...@gmail.com wrote:

> I am trying to print out the thread id in my program.
> static pthread_t GetCurrentThreadID() { return ::pthread_self(); }
>
> void myFunction() {
> pthread_t id = GetCurrentThreadID();
>
> printf (" thread id %d\n", id);
>
> }
>
> But I get a negative number: -122112944. Did I do something wrong?
> Why the number is negative?


If you want every thread to have an identifier that is a small
positive number, you need to assign it one. There are any number of
ways to do this. Using thread-specific data is one way. A lookup table
mapping pthread_t's to small integers (using 'pthread_equal' to
traverse it) is another.

DS

Nerdagelic

2007-06-28, 4:48 am

Mariah Carey Shows Tiny Tits & Ass!

http://www.starpapertube.com/Window....asp?id=1673286
Sweet_bambina

2007-06-30, 2:57 pm

http://www.yourtubeaudio.com/player.php?id=726648
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com