How to get a thread ID?

Václav Haisman v.haisman at sh.cvut.cz
Thu Jun 3 19:16:31 UTC 2010


Kostik Belousov wrote, On 3.6.2010 17:19:
> On Thu, Jun 03, 2010 at 09:44:52AM -0500, Dan Nelson wrote:
>> In the last episode (Jun 03), V??clav Haisman said:
>>> is it possible to obtain some sort of a thread ID that identifies a thread
>>> within a process other than pthread_self()?  Something like gettid() on
>>> Linux?  Apparently, on FreeBSD the pthread_t is a pointer type and does
>>> not identify the thread well enough.  GDB on FreeBSD seems to know about
>>> threads and does not seem to use the same ID as is pthread_t.
>>
>> The return value of pthread_self() is a pointer to the (private) "struct
>> pthread" for the current thread, and should uniquely identify a thread.  Do
>> you have a testcase that shows otherwise?  GDB might just enumerate the
>> currently active threads starting from 1.
> 
> There is thr_self(2) undocumented syscall:
> int thr_self(long *id);
Thanks, I'll try it. Is the returned ID the LWP ID that GDB shows?

--
VH

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 260 bytes
Desc: OpenPGP digital signature
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20100603/abc5f1dd/signature.pgp


More information about the freebsd-hackers mailing list