* Thread_Id
2005-07-23 15:02 [PATCH] quieten OOM killer noise Anton Blanchard
@ 2005-07-05 12:15 ` RVK
2005-07-05 12:55 ` Thread_Id Arjan van de Ven
2005-07-07 12:43 ` Thread_Id Benedikt Spranger
0 siblings, 2 replies; 22+ messages in thread
From: RVK @ 2005-07-05 12:15 UTC (permalink / raw)
Cc: linux-kernel
Can anyone suggest me how to get the threadId using 2.6.x kernels.
pthread_self() does not work and returns some -ve integer.
thanks
rvk
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Thread_Id
2005-07-05 12:15 ` Thread_Id RVK
@ 2005-07-05 12:55 ` Arjan van de Ven
2005-07-07 12:43 ` Thread_Id Benedikt Spranger
1 sibling, 0 replies; 22+ messages in thread
From: Arjan van de Ven @ 2005-07-05 12:55 UTC (permalink / raw)
To: rvk; +Cc: linux-kernel
On Tue, 2005-07-05 at 17:45 +0530, RVK wrote:
> Can anyone suggest me how to get the threadId using 2.6.x kernels.
> pthread_self() does not work and returns some -ve integer.
NAME
pthread_self - get the calling thread ID
SYNOPSIS
#include <pthread.h>
pthread_t pthread_self(void);
DESCRIPTION
The pthread_self() function shall return the thread ID of the
calling thread.
pthread_self() works just fine for me. But... what makes you think a
"negative" value is a failure? What interpretation are you giving to
thread ID that negative woudl be wrong? A pthreads thread ID is just a
cookie you only can use to give back to the pthread library functions in
places where it's needed...
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Thread_Id
[not found] ` <4mUJ1-5ZG-23@gated-at.bofh.it>
@ 2005-07-06 2:47 ` Robert Hancock
2005-07-14 5:33 ` Thread_Id RVK
0 siblings, 1 reply; 22+ messages in thread
From: Robert Hancock @ 2005-07-06 2:47 UTC (permalink / raw)
To: linux-kernel
RVK wrote:
> Can anyone suggest me how to get the threadId using 2.6.x kernels.
> pthread_self() does not work and returns some -ve integer.
What do you mean, negative integer? It's not an integer, it's a
pthread_t, you're not even supposed to look at it..
--
Robert Hancock Saskatoon, SK, Canada
To email, remove "nospam" from hancockr@nospamshaw.ca
Home Page: http://www.roberthancock.com/
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Thread_Id
2005-07-05 12:15 ` Thread_Id RVK
2005-07-05 12:55 ` Thread_Id Arjan van de Ven
@ 2005-07-07 12:43 ` Benedikt Spranger
2005-07-14 5:31 ` Thread_Id RVK
1 sibling, 1 reply; 22+ messages in thread
From: Benedikt Spranger @ 2005-07-07 12:43 UTC (permalink / raw)
To: rvk; +Cc: linux-kernel
Hi,
> Can anyone suggest me how to get the threadId using 2.6.x kernels.
> pthread_self() does not work and returns some -ve integer.
Let me guess: You are looking for get_tid() :-)
Bene
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Thread_Id
2005-07-07 12:43 ` Thread_Id Benedikt Spranger
@ 2005-07-14 5:31 ` RVK
0 siblings, 0 replies; 22+ messages in thread
From: RVK @ 2005-07-14 5:31 UTC (permalink / raw)
To: Benedikt Spranger; +Cc: linux-kernel
You are right Ben....gettid() will do for me. Previously for 2.4.x
(2.4.18)thread libraries I normally was using pthread_self().
Raghu
Benedikt Spranger wrote:
>Hi,
>
>
>>Can anyone suggest me how to get the threadId using 2.6.x kernels.
>>pthread_self() does not work and returns some -ve integer.
>>
>>
>
>Let me guess: You are looking for get_tid() :-)
>
>Bene
>.
>
>
>
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Thread_Id
2005-07-06 2:47 ` Thread_Id Robert Hancock
@ 2005-07-14 5:33 ` RVK
2005-07-14 7:45 ` Thread_Id Arjan van de Ven
0 siblings, 1 reply; 22+ messages in thread
From: RVK @ 2005-07-14 5:33 UTC (permalink / raw)
To: Robert Hancock; +Cc: linux-kernel
Robert Hancock wrote:
> RVK wrote:
>
>> Can anyone suggest me how to get the threadId using 2.6.x kernels.
>> pthread_self() does not work and returns some -ve integer.
>
>
> What do you mean, negative integer? It's not an integer, it's a
> pthread_t, you're not even supposed to look at it..
What is pthread_t inturn defined to ? pthread_self for 2.4.x thread
libraries return +ve number(as u have a objection me calling it as
integer :-))
Raghu
>
> --
> Robert Hancock Saskatoon, SK, Canada
> To email, remove "nospam" from hancockr@nospamshaw.ca
> Home Page: http://www.roberthancock.com/
>
> -
> To unsubscribe from this list: send the line "unsubscribe
> linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
> .
>
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Thread_Id
2005-07-14 5:33 ` Thread_Id RVK
@ 2005-07-14 7:45 ` Arjan van de Ven
2005-07-14 10:06 ` Thread_Id RVK
0 siblings, 1 reply; 22+ messages in thread
From: Arjan van de Ven @ 2005-07-14 7:45 UTC (permalink / raw)
To: rvk; +Cc: Robert Hancock, linux-kernel
On Thu, 2005-07-14 at 11:03 +0530, RVK wrote:
> Robert Hancock wrote:
>
> > RVK wrote:
> >
> >> Can anyone suggest me how to get the threadId using 2.6.x kernels.
> >> pthread_self() does not work and returns some -ve integer.
> >
> >
> > What do you mean, negative integer? It's not an integer, it's a
> > pthread_t, you're not even supposed to look at it..
>
> What is pthread_t inturn defined to ? pthread_self for 2.4.x thread
> libraries return +ve number(as u have a objection me calling it as
> integer :-))
it doesn't return a number it returns a pointer ;) or a floating point
number. You don't know :)
what it returns is a *cookie*. A cookie that you can only use to pass
back to various pthread functions.
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Thread_Id
2005-07-14 7:45 ` Thread_Id Arjan van de Ven
@ 2005-07-14 10:06 ` RVK
2005-07-14 10:30 ` Thread_Id Arjan van de Ven
2005-07-14 10:39 ` Thread_Id Ian Campbell
0 siblings, 2 replies; 22+ messages in thread
From: RVK @ 2005-07-14 10:06 UTC (permalink / raw)
To: Arjan van de Ven; +Cc: Robert Hancock, linux-kernel
Arjan van de Ven wrote:
>On Thu, 2005-07-14 at 11:03 +0530, RVK wrote:
>
>
>>Robert Hancock wrote:
>>
>>
>>
>>>RVK wrote:
>>>
>>>
>>>
>>>>Can anyone suggest me how to get the threadId using 2.6.x kernels.
>>>>pthread_self() does not work and returns some -ve integer.
>>>>
>>>>
>>>What do you mean, negative integer? It's not an integer, it's a
>>>pthread_t, you're not even supposed to look at it..
>>>
>>>
>>What is pthread_t inturn defined to ? pthread_self for 2.4.x thread
>>libraries return +ve number(as u have a objection me calling it as
>>integer :-))
>>
>>
>
>it doesn't return a number it returns a pointer ;) or a floating point
>number. You don't know :)
>
>what it returns is a *cookie*. A cookie that you can only use to pass
>back to various pthread functions.
>
>
>
Hahaha......common. Please clarify following....
SYNOPSIS
#include <pthread.h>
pthread_t pthread_self(void);
DESCRIPTION
pthread_self return the thread identifier for the calling thread.
bits/pthreadtypes.h:150:typedef unsigned long int pthread_t;
rvk
>-
>To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at http://vger.kernel.org/majordomo-info.html
>Please read the FAQ at http://www.tux.org/lkml/
>.
>
>
>
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Thread_Id
2005-07-14 10:06 ` Thread_Id RVK
@ 2005-07-14 10:30 ` Arjan van de Ven
2005-07-14 11:20 ` Thread_Id RVK
2005-07-14 10:39 ` Thread_Id Ian Campbell
1 sibling, 1 reply; 22+ messages in thread
From: Arjan van de Ven @ 2005-07-14 10:30 UTC (permalink / raw)
To: rvk; +Cc: Robert Hancock, linux-kernel
On Thu, 2005-07-14 at 15:36 +0530, RVK wrote:
> >
> >it doesn't return a number it returns a pointer ;) or a floating point
> >number. You don't know :)
> >
> >what it returns is a *cookie*. A cookie that you can only use to pass
> >back to various pthread functions.
> >
> >
> >
> Hahaha......common. Please clarify following....
I'm missing the joke
> SYNOPSIS
> #include <pthread.h>
>
> pthread_t pthread_self(void);
>
> DESCRIPTION
> pthread_self return the thread identifier for the calling thread.
*identifier*.
It doesn't give a meaning beyond that, and if you look at other pthread
manpages (say pthread_join) it just wants that identifier back. If you
want to attach meaning to a thread identifier, please come up with a
manpage/standard that actually defines the meaning of it.
>
> bits/pthreadtypes.h:150:typedef unsigned long int pthread_t;
and here you
1) look at implementation details of your specific threading
implementation and
2) you prove that your analysis is wrong since the implementation you
look at defines it as *unsigned* so it can't be negative. So what your
app does is clearly wrong even within the implementation you look at.
Other implementations are allowed to use different types for this. In
fact, I'd be surprised if NPTL and LinuxThreads would have the same
type... (they'll have the same size for ABI compat reasons of course,
but type... not so sure).
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Thread_Id
2005-07-14 10:06 ` Thread_Id RVK
2005-07-14 10:30 ` Thread_Id Arjan van de Ven
@ 2005-07-14 10:39 ` Ian Campbell
2005-07-14 11:02 ` Thread_Id RVK
1 sibling, 1 reply; 22+ messages in thread
From: Ian Campbell @ 2005-07-14 10:39 UTC (permalink / raw)
To: rvk; +Cc: Arjan van de Ven, Robert Hancock, linux-kernel
On Thu, 2005-07-14 at 15:36 +0530, RVK wrote:
> bits/pthreadtypes.h:150:typedef unsigned long int pthread_t;
That's an implementation detail which you cannot determine any
information from.
What Arjan is saying is that pthread_t is a cookie -- this means that
you cannot interpret it in any way, it is just a "thing" which you can
pass back to the API, that pthread_t happens to be typedef'd to unsigned
long int is irrelevant.
Ian.
--
Ian Campbell
Current Noise: Nile - Annihilation Of The Wicked
Don't tell me what you dreamed last night for I've been reading Freud.
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Thread_Id
2005-07-14 10:39 ` Thread_Id Ian Campbell
@ 2005-07-14 11:02 ` RVK
2005-07-14 11:16 ` Thread_Id Ian Campbell
2005-07-14 14:28 ` Thread_Id Robert Hancock
0 siblings, 2 replies; 22+ messages in thread
From: RVK @ 2005-07-14 11:02 UTC (permalink / raw)
To: Ian Campbell; +Cc: Arjan van de Ven, Robert Hancock, linux-kernel
Ian Campbell wrote:
>On Thu, 2005-07-14 at 15:36 +0530, RVK wrote:
>
>
>
>>bits/pthreadtypes.h:150:typedef unsigned long int pthread_t;
>>
>>
>
>That's an implementation detail which you cannot determine any
>information from.
>
>What Arjan is saying is that pthread_t is a cookie -- this means that
>you cannot interpret it in any way, it is just a "thing" which you can
>pass back to the API, that pthread_t happens to be typedef'd to unsigned
>long int is irrelevant.
>
>
>
Do you want to say for both 2.6.x and 2.4.x I should interpret that way ?
rvk
>Ian.
>
>--
>Ian Campbell
>Current Noise: Nile - Annihilation Of The Wicked
>
>Don't tell me what you dreamed last night for I've been reading Freud.
>.
>
>
>
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Thread_Id
2005-07-14 11:02 ` Thread_Id RVK
@ 2005-07-14 11:16 ` Ian Campbell
2005-07-14 11:24 ` Thread_Id RVK
2005-07-14 14:28 ` Thread_Id Robert Hancock
1 sibling, 1 reply; 22+ messages in thread
From: Ian Campbell @ 2005-07-14 11:16 UTC (permalink / raw)
To: rvk; +Cc: Arjan van de Ven, Robert Hancock, linux-kernel
On Thu, 2005-07-14 at 16:32 +0530, RVK wrote:
> Ian Campbell wrote:
> >What Arjan is saying is that pthread_t is a cookie -- this means that
> >you cannot interpret it in any way, it is just a "thing" which you can
> >pass back to the API, that pthread_t happens to be typedef'd to unsigned
> >long int is irrelevant.
> Do you want to say for both 2.6.x and 2.4.x I should interpret that way ?
As I understand it, yes, you should never try and assign any meaning to
the values. The fact that you may have been able to find some apparent
meaning under 2.4 is just a coincidence.
Ian.
--
Ian Campbell
Current Noise: Nile - Annihilation Of The Wicked
BOFH excuse #127:
Sticky bits on disk.
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Thread_Id
2005-07-14 10:30 ` Thread_Id Arjan van de Ven
@ 2005-07-14 11:20 ` RVK
2005-07-14 12:25 ` Thread_Id Arjan van de Ven
0 siblings, 1 reply; 22+ messages in thread
From: RVK @ 2005-07-14 11:20 UTC (permalink / raw)
To: Arjan van de Ven; +Cc: Robert Hancock, linux-kernel
Arjan van de Ven wrote:
>On Thu, 2005-07-14 at 15:36 +0530, RVK wrote:
>
>
>
>>>it doesn't return a number it returns a pointer ;) or a floating point
>>>number. You don't know :)
>>>
>>>what it returns is a *cookie*. A cookie that you can only use to pass
>>>back to various pthread functions.
>>>
>>>
>>>
>>>
>>>
>>Hahaha......common. Please clarify following....
>>
>>
>
>I'm missing the joke
>
>
>
Its not a joke its a confusion created by the thread identifier.
>>SYNOPSIS
>> #include <pthread.h>
>>
>> pthread_t pthread_self(void);
>>
>>DESCRIPTION
>> pthread_self return the thread identifier for the calling thread.
>>
>>
>
>*identifier*.
>It doesn't give a meaning beyond that, and if you look at other pthread
>manpages (say pthread_join) it just wants that identifier back. If you
>want to attach meaning to a thread identifier, please come up with a
>manpage/standard that actually defines the meaning of it.
>
>
>
>>bits/pthreadtypes.h:150:typedef unsigned long int pthread_t;
>>
>>
>
>and here you
>1) look at implementation details of your specific threading
>implementation and
>2) you prove that your analysis is wrong since the implementation you
>look at defines it as *unsigned* so it can't be negative. So what your
>app does is clearly wrong even within the implementation you look at.
>
>
>
>
So then what is the meaning of that typedef and why its still there ?
>Other implementations are allowed to use different types for this. In
>fact, I'd be surprised if NPTL and LinuxThreads would have the same
>type... (they'll have the same size for ABI compat reasons of course,
>but type... not so sure).
>
>
>
I haven't faced the same returns with 2.4.18. So why is it so with 2.6.x
kernels ? pthread_self() on 2.4.18 was returning the same as gettid()
with 2.6.x.
rvk
>.
>
>
>
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Thread_Id
2005-07-14 11:16 ` Thread_Id Ian Campbell
@ 2005-07-14 11:24 ` RVK
2005-07-14 23:02 ` Thread_Id J.A. Magallon
0 siblings, 1 reply; 22+ messages in thread
From: RVK @ 2005-07-14 11:24 UTC (permalink / raw)
To: Ian Campbell; +Cc: Arjan van de Ven, Robert Hancock, linux-kernel
Ian Campbell wrote:
>On Thu, 2005-07-14 at 16:32 +0530, RVK wrote:
>
>
>>Ian Campbell wrote:
>>
>>
>>>What Arjan is saying is that pthread_t is a cookie -- this means that
>>>you cannot interpret it in any way, it is just a "thing" which you can
>>>pass back to the API, that pthread_t happens to be typedef'd to unsigned
>>>long int is irrelevant.
>>>
>>>
>>Do you want to say for both 2.6.x and 2.4.x I should interpret that way ?
>>
>>
>
>As I understand it, yes, you should never try and assign any meaning to
>the values. The fact that you may have been able to find some apparent
>meaning under 2.4 is just a coincidence.
>
>
>
Iam sorry I don't agree on this. This confusion have created only becoz
of the different behavior of pthread_self() on 2.4.18 and 2.6.x kernels.
And Iam looking for clarifying my doubt. I can't digest this at all.
rvk
>Ian.
>
>--
>Ian Campbell
>Current Noise: Nile - Annihilation Of The Wicked
>
>BOFH excuse #127:
>
>Sticky bits on disk.
>.
>
>
>
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Thread_Id
2005-07-14 11:20 ` Thread_Id RVK
@ 2005-07-14 12:25 ` Arjan van de Ven
2005-07-14 12:39 ` Thread_Id Jakub Jelinek
0 siblings, 1 reply; 22+ messages in thread
From: Arjan van de Ven @ 2005-07-14 12:25 UTC (permalink / raw)
To: rvk; +Cc: Robert Hancock, linux-kernel
> >
> So then what is the meaning of that typedef and why its still there ?
the typedef means that the *IMPLEMENTATION* uses an unsigned long to
store its cookie in.
>
> >Other implementations are allowed to use different types for this. In
> >fact, I'd be surprised if NPTL and LinuxThreads would have the same
> >type... (they'll have the same size for ABI compat reasons of course,
> >but type... not so sure).
> >
> >
> >
> I haven't faced the same returns with 2.4.18. So why is it so with 2.6.x
> kernels ? pthread_self() on 2.4.18 was returning the same as gettid()
> with 2.6.x.
pure luck. NPTL threading uses it to store a pointer to per thread info
structure; other threading (linuxthreads) may have stored a pid there to
identify the internal thread. nptl is 2.6 only so you might have
switched implementation of threading when you switched kernels.
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Thread_Id
2005-07-14 12:25 ` Thread_Id Arjan van de Ven
@ 2005-07-14 12:39 ` Jakub Jelinek
2005-07-14 13:08 ` Thread_Id Benedikt Spranger
2005-07-14 13:49 ` Thread_Id RVK
0 siblings, 2 replies; 22+ messages in thread
From: Jakub Jelinek @ 2005-07-14 12:39 UTC (permalink / raw)
To: Arjan van de Ven; +Cc: rvk, Robert Hancock, linux-kernel
On Thu, Jul 14, 2005 at 02:25:43PM +0200, Arjan van de Ven wrote:
> pure luck. NPTL threading uses it to store a pointer to per thread info
> structure; other threading (linuxthreads) may have stored a pid there to
> identify the internal thread. nptl is 2.6 only so you might have
> switched implementation of threading when you switched kernels.
Actually, in linuxthreads what pthread_self () returned has the first slot
in its internal threads array (up to max number of supported threads)
that was unused at thread creation time in the low order bits and sequence
number of thread creation in its high order bits.
So unless you are using yet another threading library (I thought NGPT
is dead for years...), the claim that you get the same numbers from
gettid() syscall under NPTL as pthread_self () gives you under LinuxThreads
is simply not true. And you certainly shouldn't be using gettid ()
syscall in NPTL, as it is just an implementation detail that there is
a 1:1 mapping between NPTL threads and kernel threads. It can change
at any time.
Jakub
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Thread_Id
2005-07-14 12:39 ` Thread_Id Jakub Jelinek
@ 2005-07-14 13:08 ` Benedikt Spranger
2005-07-14 13:49 ` Thread_Id RVK
1 sibling, 0 replies; 22+ messages in thread
From: Benedikt Spranger @ 2005-07-14 13:08 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Arjan van de Ven, rvk, Robert Hancock, linux-kernel
> And you certainly shouldn't be using gettid () syscall in NPTL, as it
> is just an implementation detail that there is a 1:1 mapping between
> NPTL threads and kernel threads. It can change at any time.
Maybe I missed the point, but I thought the 1:1 mapping between NPTL
threads and kernel threads is one of the advantages of NPTL and the idea
of a userland scheduler is quite dead.
So please let gettid do what man gettid assures:
gettid returns the thread ID of the current process. This is equal to
the process ID (as returned by getpid(2)), unless the process is part
of a thread group (created by specifying the CLONE_THREAD flag to the
clone(2) system call). All processes in the same thread group have the
same PID, but each one has a unique TID.
Bene
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Thread_Id
2005-07-14 12:39 ` Thread_Id Jakub Jelinek
2005-07-14 13:08 ` Thread_Id Benedikt Spranger
@ 2005-07-14 13:49 ` RVK
1 sibling, 0 replies; 22+ messages in thread
From: RVK @ 2005-07-14 13:49 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Arjan van de Ven, Robert Hancock, linux-kernel
Jakub Jelinek wrote:
>On Thu, Jul 14, 2005 at 02:25:43PM +0200, Arjan van de Ven wrote:
>
>
>>pure luck. NPTL threading uses it to store a pointer to per thread info
>>structure; other threading (linuxthreads) may have stored a pid there to
>>identify the internal thread. nptl is 2.6 only so you might have
>>switched implementation of threading when you switched kernels.
>>
>>
>
>Actually, in linuxthreads what pthread_self () returned has the first slot
>in its internal threads array (up to max number of supported threads)
>that was unused at thread creation time in the low order bits and sequence
>number of thread creation in its high order bits.
>So unless you are using yet another threading library (I thought NGPT
>is dead for years...), the claim that you get the same numbers from
>gettid() syscall under NPTL as pthread_self () gives you under LinuxThreads
>is simply not true. And you certainly shouldn't be using gettid ()
>syscall in NPTL, as it is just an implementation detail that there is
>a 1:1 mapping between NPTL threads and kernel threads. It can change
>at any time.
>
>
>
Which ever is the implementation its expected to be backward compatible.
Especially thread libraries. As lot of applications using that.
rvk
> Jakub
>
>
>
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Thread_Id
2005-07-14 11:02 ` Thread_Id RVK
2005-07-14 11:16 ` Thread_Id Ian Campbell
@ 2005-07-14 14:28 ` Robert Hancock
1 sibling, 0 replies; 22+ messages in thread
From: Robert Hancock @ 2005-07-14 14:28 UTC (permalink / raw)
To: rvk; +Cc: Ian Campbell, Arjan van de Ven, linux-kernel
RVK wrote:
> Ian Campbell wrote:
>
>> On Thu, 2005-07-14 at 15:36 +0530, RVK wrote:
>>
>>
>>
>>> bits/pthreadtypes.h:150:typedef unsigned long int pthread_t;
>>>
>>
>>
>> That's an implementation detail which you cannot determine any
>> information from.
>>
>> What Arjan is saying is that pthread_t is a cookie -- this means that
>> you cannot interpret it in any way, it is just a "thing" which you can
>> pass back to the API, that pthread_t happens to be typedef'd to unsigned
>> long int is irrelevant.
>>
>>
>>
> Do you want to say for both 2.6.x and 2.4.x I should interpret that way ?
>
> rvk
Indeed, for ANY OS using pthreads it should be interpreted that way..
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Thread_Id
2005-07-14 11:24 ` Thread_Id RVK
@ 2005-07-14 23:02 ` J.A. Magallon
2005-07-15 6:09 ` Thread_Id RVK
0 siblings, 1 reply; 22+ messages in thread
From: J.A. Magallon @ 2005-07-14 23:02 UTC (permalink / raw)
To: rvk; +Cc: Ian Campbell, Arjan van de Ven, Robert Hancock, linux-kernel
On 07.14, RVK wrote:
> Ian Campbell wrote:
>
> >On Thu, 2005-07-14 at 16:32 +0530, RVK wrote:
> >
> >
> >>Ian Campbell wrote:
> >>
> >>
> >>>What Arjan is saying is that pthread_t is a cookie -- this means that
> >>>you cannot interpret it in any way, it is just a "thing" which you can
> >>>pass back to the API, that pthread_t happens to be typedef'd to unsigned
> >>>long int is irrelevant.
> >>>
> >>>
> >>Do you want to say for both 2.6.x and 2.4.x I should interpret that way ?
> >>
> >>
> >
> >As I understand it, yes, you should never try and assign any meaning to
> >the values. The fact that you may have been able to find some apparent
> >meaning under 2.4 is just a coincidence.
> >
> >
> >
> Iam sorry I don't agree on this. This confusion have created only becoz
> of the different behavior of pthread_self() on 2.4.18 and 2.6.x kernels.
> And Iam looking for clarifying my doubt. I can't digest this at all.
>
It is simple: none ever never told you that a pthread_t has nothing to do
with a pid. pthreads is a standard and portable implementation that
guarantees you can port _pthread_ code between posix systems. It uses
an internal opaque type to identify threads, but you should never relay on
it have nothing to do with pids. The fact that somewhere-in-time-in-some-os
the pthread_t equals the pid/tid/ etc is just pure chance. If you had
code relaying on this, it is just broken. Where is stated if pthread_t is
the tid, an index into a table internal to pthread library, a pointer
to an struct (mmm, bloken on 64 bits?) or what ?
Whatif:
- you swith kernels and thread library implementation ?
- you go solaris (it has user level threads ?)
I think one of the sources of the confussion is that:
- man pages about system calls talk about 'threads', but that should be
read as 'sibling _processes_ created via clone(CLONE_THREAD) syscall'.
- man pages about phthreads library also talk about 'threads', but that
should be read as 'posix threads created via pthread_create'.
And none guarantees that both 'threads' are the same.
If you just want to use gettid(), don't go further that clone().
If you use pthread_create(), forget about gettid().
(AFAIK ;) )
--
J.A. Magallon <jamagallon()able!es> \ Software is like sex:
werewolf!able!es \ It's better when it's free
Mandriva Linux release 2006.0 (Cooker) for i586
Linux 2.6.12-jam9 (gcc 4.0.1 (4.0.1-0.2mdk for Mandriva Linux release 2006.0))
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Thread_Id
2005-07-14 23:02 ` Thread_Id J.A. Magallon
@ 2005-07-15 6:09 ` RVK
2005-07-15 6:18 ` Thread_Id Ian Campbell
0 siblings, 1 reply; 22+ messages in thread
From: RVK @ 2005-07-15 6:09 UTC (permalink / raw)
To: J.A. Magallon
Cc: Ian Campbell, Arjan van de Ven, Robert Hancock, linux-kernel
J.A. Magallon wrote:
>On 07.14, RVK wrote:
>
>
>>Ian Campbell wrote:
>>
>>
>>
>>>On Thu, 2005-07-14 at 16:32 +0530, RVK wrote:
>>>
>>>
>>>
>>>
>>>>Ian Campbell wrote:
>>>>
>>>>
>>>>
>>>>
>>>>>What Arjan is saying is that pthread_t is a cookie -- this means that
>>>>>you cannot interpret it in any way, it is just a "thing" which you can
>>>>>pass back to the API, that pthread_t happens to be typedef'd to unsigned
>>>>>long int is irrelevant.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>Do you want to say for both 2.6.x and 2.4.x I should interpret that way ?
>>>>
>>>>
>>>>
>>>>
>>>As I understand it, yes, you should never try and assign any meaning to
>>>the values. The fact that you may have been able to find some apparent
>>>meaning under 2.4 is just a coincidence.
>>>
>>>
>>>
>>>
>>>
>>Iam sorry I don't agree on this. This confusion have created only becoz
>>of the different behavior of pthread_self() on 2.4.18 and 2.6.x kernels.
>>And Iam looking for clarifying my doubt. I can't digest this at all.
>>
>>
>>
>
>It is simple: none ever never told you that a pthread_t has nothing to do
>with a pid. pthreads is a standard and portable implementation that
>guarantees you can port _pthread_ code between posix systems. It uses
>an internal opaque type to identify threads, but you should never relay on
>it have nothing to do with pids. The fact that somewhere-in-time-in-some-os
>the pthread_t equals the pid/tid/ etc is just pure chance. If you had
>code relaying on this, it is just broken. Where is stated if pthread_t is
>the tid, an index into a table internal to pthread library, a pointer
>to an struct (mmm, bloken on 64 bits?) or what ?
>
>
>
Understood on pid/tid and thread identifier diffrentiation. The question
now is why pthread_t is typedef as unsigned long ?
>Whatif:
>- you swith kernels and thread library implementation ?
>- you go solaris (it has user level threads ?)
>
>I think one of the sources of the confussion is that:
>- man pages about system calls talk about 'threads', but that should be
> read as 'sibling _processes_ created via clone(CLONE_THREAD) syscall'.
>- man pages about phthreads library also talk about 'threads', but that
> should be read as 'posix threads created via pthread_create'.
>And none guarantees that both 'threads' are the same.
>
>
>
Yes its very important to have clarity in the manuals on this.
>If you just want to use gettid(), don't go further that clone().
>If you use pthread_create(), forget about gettid().
>
>
>
Does the man pages for pthread_create or clone or gettid states this ?
rvk
>(AFAIK ;) )
>
>--
>J.A. Magallon <jamagallon()able!es> \ Software is like sex:
>werewolf!able!es \ It's better when it's free
>Mandriva Linux release 2006.0 (Cooker) for i586
>Linux 2.6.12-jam9 (gcc 4.0.1 (4.0.1-0.2mdk for Mandriva Linux release 2006.0))
>
>
>.
>
>
>
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Thread_Id
2005-07-15 6:09 ` Thread_Id RVK
@ 2005-07-15 6:18 ` Ian Campbell
0 siblings, 0 replies; 22+ messages in thread
From: Ian Campbell @ 2005-07-15 6:18 UTC (permalink / raw)
To: rvk; +Cc: J.A. Magallon, Arjan van de Ven, Robert Hancock, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 345 bytes --]
On Fri, 2005-07-15 at 11:39 +0530, RVK wrote:
> Understood on pid/tid and thread identifier diffrentiation. The question
> now is why pthread_t is typedef as unsigned long ?
It's just an arbitrary type that is big enough to contain the cookie.
Ian.
--
Ian Campbell
It is better to give than to lend, and it costs about the same.
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 22+ messages in thread
end of thread, other threads:[~2005-07-15 6:19 UTC | newest]
Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <4mfcK-UT-25@gated-at.bofh.it>
[not found] ` <4mUJ1-5ZG-23@gated-at.bofh.it>
2005-07-06 2:47 ` Thread_Id Robert Hancock
2005-07-14 5:33 ` Thread_Id RVK
2005-07-14 7:45 ` Thread_Id Arjan van de Ven
2005-07-14 10:06 ` Thread_Id RVK
2005-07-14 10:30 ` Thread_Id Arjan van de Ven
2005-07-14 11:20 ` Thread_Id RVK
2005-07-14 12:25 ` Thread_Id Arjan van de Ven
2005-07-14 12:39 ` Thread_Id Jakub Jelinek
2005-07-14 13:08 ` Thread_Id Benedikt Spranger
2005-07-14 13:49 ` Thread_Id RVK
2005-07-14 10:39 ` Thread_Id Ian Campbell
2005-07-14 11:02 ` Thread_Id RVK
2005-07-14 11:16 ` Thread_Id Ian Campbell
2005-07-14 11:24 ` Thread_Id RVK
2005-07-14 23:02 ` Thread_Id J.A. Magallon
2005-07-15 6:09 ` Thread_Id RVK
2005-07-15 6:18 ` Thread_Id Ian Campbell
2005-07-14 14:28 ` Thread_Id Robert Hancock
2005-07-23 15:02 [PATCH] quieten OOM killer noise Anton Blanchard
2005-07-05 12:15 ` Thread_Id RVK
2005-07-05 12:55 ` Thread_Id Arjan van de Ven
2005-07-07 12:43 ` Thread_Id Benedikt Spranger
2005-07-14 5:31 ` Thread_Id RVK
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox