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 ]
|