Re: Negative numbers for thread ID - why ?
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Re: Negative numbers for thread ID - why ?




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Re: Negative numbers for thread ID - why ?  
loic-dev@gmx.net


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-18-07 12:28 AM

Hi Mark,

> I am running FC6 machine (i386 based).
> I am trying the follwing:
>
>  create a thread with pthread_create().
>  in the thread function, I have:
>  printf("tid in thread_func=%d\n",(int)pthread_self());
>
>  I get negative number for the thread id, for example:
>
>  tid in thread2_func=-1218974832
>
>  Why is it so ?
>  I saw in some places usage of this method (pthread_self()),but
> it returned non negative numbers.
>
> Any ideas?

As stated by POSIX, pthread_t is an opaque type. The internal
representation should not matter to you. That's why there is function
like /pthread_equal()/ to compare two thread IDs BTW.

Now, it is not uncommon to print out the thread id of a given thread,
for debugging purpose for instance. If you want to do so, you must then
know how the underlying Pthreads implementation represents the thread
id. For your FC6, it's actually a pointer, so you should be using the
"%p" formater. On former Linux system with LinuxThreads, things would
have been different, because the thread id was actually an index in a
table (which may explain the "%d").

As mentioned by David already, if you undertake this path, you should
remind yourself that the resulting program, besides of being not POSIX
conform, may not be portable.

HTH,
Loic.






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 01:52 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register