Unix Programming - Re: Negative numbers for thread ID - why ?

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > January 2007 > Re: Negative numbers for thread ID - why ?





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: Negative numbers for thread ID - why ?
Lew Pitcher

2007-01-17, 1:17 pm


markryde@gmail.com wrote:
> Hello,
>
> 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 ?


Why? Because you made it so.
Remember, the "%d" printf format string tells printf to interpret the
incoming value as a *signed* integer. The data you got back from
pthread_self(), when cast to an integer value and interpreted as a
signed integer, had a value of -1218974832. Had you told printf() to
print it as "%u", you would have seen a different printed value because
you would have told printf() to interpret the number as an unsigned
integer.

> I saw in some places usage of this method (pthread_self()),but
> it returned non negative numbers.


This usage will print non-negative values for pthread_self() values
that are smaller than INT_MAX + 1

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com