Thread_Id
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 1 line · RVK
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..
Signature · 3 lines
Robert Hancock Saskatoon, SK, Canada To email, remove "nospam" from [email protected] Home Page: http://www.roberthancock.com/
Quoted 8 lines · Robert Hancock
Quoted 2 lines · RVK
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
Quoted 13 lines
Signature · 11 lines
-- Robert Hancock Saskatoon, SK, Canada To email, remove "nospam" from [email protected] Home Page: http://www.roberthancock.com/ - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ .
Quoted 8 lines · RVK
Quoted 6 lines · Robert Hancock
Quoted 2 lines · RVK
Can anyone suggest me how to get the threadId using 2.6.x kernels.
pthread_self()does not work and returns some -ve integer.
Quoted 6 lines
Quoted 2 lines
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_tinturn defined to ?pthread_selffor 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.
Quoted 25 lines · Arjan van de Ven
Quoted 12 lines · RVK
Quoted 8 lines · Robert Hancock
Quoted 4 lines · RVK
Can anyone suggest me how to get the threadId using 2.6.x kernels.
pthread_self()does not work and returns some -ve integer.Quoted 9 lines
Quoted 4 lines
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_tinturn defined to ?pthread_selffor 2.4.x thread libraries return +ve number(as u have a objection me calling it as integer :-))
Quoted 8 lines
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
Quoted 9 lines
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
.
Quoted 10 lines · RVK
Quoted 9 lines
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
Quoted 7 lines
SYNOPSIS
#include <pthread.h> pthread_t pthread_self(void);DESCRIPTION
pthread_selfreturn 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.
Quoted 2 lines
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).
Quoted 14 lines · Arjan van de Ven
Quoted 10 lines · RVK
Quoted 10 lines
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.
Quoted 8 lines
Quoted 3 lines
Hahaha......common. Please clarify following....
I'm missing the joke
Its not a joke its a confusion created by the thread identifier.
Quoted 22 lines
Quoted 9 lines
SYNOPSIS
#include <pthread.h> pthread_t pthread_self(void);DESCRIPTION
pthread_selfreturn the thread identifier for the calling thread.*identifier*.
It doesn't give a meaning beyond that, and if you look at other pthread manpages (saypthread_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.Quoted 3 lines
bits/pthreadtypes.h:150:typedef unsigned long int
pthread_t;
Quoted 10 lines
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 ?
Quoted 7 lines
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
Quoted 4 lines
.
Quoted 3 lines
Quoted 2 lines
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.
Quoted 11 lines
Quoted 8 lines
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 asgettid()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.
Quoted 4 lines · Arjan van de Ven
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
Quoted 3 lines
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
Quoted 10 lines · Jakub Jelinek
Quoted 6 lines · Arjan van de Ven
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.
Quoted 14 lines
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 fromgettid()syscall under NPTL aspthread_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
Quoted 4 lines
Jakub
Quoted 1 line · RVK
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.
Signature · 4 lines
Ian Campbell Current Noise: Nile - Annihilation Of The Wicked Don't tell me what you dreamed last night for I've been reading Freud.
Quoted 8 lines · Ian Campbell
Quoted 3 lines · RVK
bits/pthreadtypes.h:150:typedef unsigned long int
pthread_t;
Quoted 10 lines
That's an implementation detail which you cannot determine any information from.
What Arjan is saying is that
pthread_tis 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, thatpthread_thappens 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
Quoted 11 lines
Ian.
--
Ian Campbell
Current Noise: Nile - Annihilation Of The WickedDon't tell me what you dreamed last night for I've been reading Freud. .
Quoted 6 lines · RVK
Quoted 4 lines · Ian Campbell
What Arjan is saying is that
pthread_tis 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, thatpthread_thappens 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.
Signature · 6 lines
Ian Campbell Current Noise: Nile - Annihilation Of The Wicked BOFH excuse #127: Sticky bits on disk.
Quoted 12 lines · Ian Campbell
Quoted 9 lines · RVK
Quoted 6 lines · Ian Campbell
What Arjan is saying is that
pthread_tis 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, thatpthread_thappens to be typedef'd to unsigned long int is irrelevant.
Quoted 10 lines
Quoted 3 lines
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
Quoted 13 lines
Ian.
--
Ian Campbell
Current Noise: Nile - Annihilation Of The WickedBOFH excuse #127:
Sticky bits on disk.
.
Quoted 24 lines · RVK
Quoted 12 lines · Ian Campbell
Quoted 9 lines · RVK
Quoted 6 lines · Ian Campbell
What Arjan is saying is that
pthread_tis 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, thatpthread_thappens to be typedef'd to unsigned long int is irrelevant.Quoted 10 lines
Quoted 3 lines
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.
Quoted 4 lines
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))
Quoted 45 lines · J.A. Magallon
Quoted 35 lines · RVK
Quoted 18 lines · Ian Campbell
Quoted 13 lines · RVK
Quoted 8 lines · Ian Campbell
What Arjan is saying is that
pthread_tis 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, thatpthread_thappens to be typedef'd to unsigned long int is irrelevant.Quoted 13 lines
Quoted 5 lines
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.
Quoted 6 lines
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.
Quoted 12 lines
It is simple: none ever never told you that a
pthread_thas 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 thepthread_tequals the pid/tid/ etc is just pure chance. If you had code relaying on this, it is just broken. Where is stated ifpthread_tis 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 ?
Quoted 4 lines
Whatif:
- you swith kernels and thread library implementation ?
- you go solaris (it has user level threads ?)
Quoted 9 lines
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 viaclone(CLONE_THREAD)syscall'.
- man pages about phthreads library also talk about 'threads', but that should be read as 'posix threads created viapthread_create'.
And none guarantees that both 'threads' are the same.
Yes its very important to have clarity in the manuals on this.
Quoted 5 lines
If you just want to use
gettid(), don't go further thatclone(). If you usepthread_create(), forget aboutgettid().
Does the man pages for pthread_create or clone or gettid states this ?
rvk
Quoted 13 lines
(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)).
Quoted 2 lines · RVK
Understood on pid/tid and thread identifier diffrentiation. The question now is why
pthread_tis typedef as unsigned long ?
It's just an arbitrary type that is big enough to contain the cookie.
Ian.
Signature · 3 lines
Ian Campbell It is better to give than to lend, and it costs about the same.
Quoted 20 lines · RVK
Quoted 8 lines · Ian Campbell
Quoted 2 lines · RVK
bits/pthreadtypes.h:150:typedef unsigned long int
pthread_t;Quoted 10 lines
That's an implementation detail which you cannot determine any information from.
What Arjan is saying is that
pthread_tis 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, thatpthread_thappens to be typedef'd to unsigned long int is irrelevant.
Quoted 3 lines
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..