<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How does a thread get its own thread id? in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/how-does-a-thread-get-its-own-thread-id/m-p/2644627#M833418</link>
    <description>Thank you two gentlement for your responses.&lt;BR /&gt;&lt;BR /&gt;I was able to get the thread id returned by GlancePlus by using the pstat_getlwp() function. To get the thread id for each thread, first I used pthread_self() to get the thread number, then in the arguments to pstat_getlwp I set elemcount = 1 and index = pthread_self() - 1. I had to subtract 1 because pthread_self starts at 1 but lwpid apparently starts with index base 0.&lt;BR /&gt;&lt;BR /&gt;Thanks again!</description>
    <pubDate>Tue, 15 Jan 2002 15:41:50 GMT</pubDate>
    <dc:creator>Todd Larchuk</dc:creator>
    <dc:date>2002-01-15T15:41:50Z</dc:date>
    <item>
      <title>How does a thread get its own thread id?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-does-a-thread-get-its-own-thread-id/m-p/2644624#M833415</link>
      <description>GlancePlus running in HPUX 11 has a metric called THREAD_THREAD_ID that gives the unique id for each thread as seen by the kernel scheduler. How can the thread get this id so I can figure out which thread id in glance corresponds to each thread in the process. I can get the thread number, i.e. 0 is main thread, 1, 2, ..., N-1 where N is the number of threads. That doesn't help when glanceplus give something like a pid (ex. 17215). I tried getpid() but that gives the pid of the parent process.</description>
      <pubDate>Mon, 14 Jan 2002 20:00:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-does-a-thread-get-its-own-thread-id/m-p/2644624#M833415</guid>
      <dc:creator>Todd Larchuk</dc:creator>
      <dc:date>2002-01-14T20:00:42Z</dc:date>
    </item>
    <item>
      <title>Re: How does a thread get its own thread id?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-does-a-thread-get-its-own-thread-id/m-p/2644625#M833416</link>
      <description>Have you looked at pthread_self?? Are you trying to gather this info outside of the application?&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
      <pubDate>Mon, 14 Jan 2002 20:31:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-does-a-thread-get-its-own-thread-id/m-p/2644625#M833416</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2002-01-14T20:31:19Z</dc:date>
    </item>
    <item>
      <title>Re: How does a thread get its own thread id?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-does-a-thread-get-its-own-thread-id/m-p/2644626#M833417</link>
      <description>try pstat_getlwp (2).  It can return info (including lwpid) for each of the threads associated with a process.  Here's a simple example (run on 11i):&lt;BR /&gt;&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;ERRNO.H&gt;&lt;BR /&gt;#include &lt;SYS&gt;&lt;BR /&gt;#include &lt;SYS&gt;&lt;BR /&gt;&lt;BR /&gt;main(argc,argv)&lt;BR /&gt;int argc;&lt;BR /&gt;char *argv[];&lt;BR /&gt;{&lt;BR /&gt;        int64_t mylwpid;&lt;BR /&gt;        pid_t mypid;&lt;BR /&gt;        int thread,ret;&lt;BR /&gt;        struct lwp_status tbuf;&lt;BR /&gt;&lt;BR /&gt;        mypid = getpid();&lt;BR /&gt;        thread = 0;&lt;BR /&gt;&lt;BR /&gt;        if(ret = pstat_getlwp(&amp;amp;tbuf,sizeof(struct lwp_status),1,thread,mypid) &amp;lt; 0) { &lt;BR /&gt;          perror("pstat_getlwp"); &lt;BR /&gt;          sleep(20);&lt;BR /&gt;          exit(-1); &lt;BR /&gt;        } &lt;BR /&gt;        &lt;BR /&gt;        printf("my pid is %d, lwpid is %lld\n",mypid,tbuf.lwp_lwpid);&lt;BR /&gt;        sleep(20);&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&amp;gt; cc getlwpid.c&lt;BR /&gt;&amp;gt; a.out&lt;BR /&gt;my pid is 25486, lwpid is 469195&lt;BR /&gt;&lt;BR /&gt;&lt;/SYS&gt;&lt;/SYS&gt;&lt;/ERRNO.H&gt;&lt;/STDIO.H&gt;</description>
      <pubDate>Mon, 14 Jan 2002 21:46:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-does-a-thread-get-its-own-thread-id/m-p/2644626#M833417</guid>
      <dc:creator>Kirby Collins</dc:creator>
      <dc:date>2002-01-14T21:46:46Z</dc:date>
    </item>
    <item>
      <title>Re: How does a thread get its own thread id?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-does-a-thread-get-its-own-thread-id/m-p/2644627#M833418</link>
      <description>Thank you two gentlement for your responses.&lt;BR /&gt;&lt;BR /&gt;I was able to get the thread id returned by GlancePlus by using the pstat_getlwp() function. To get the thread id for each thread, first I used pthread_self() to get the thread number, then in the arguments to pstat_getlwp I set elemcount = 1 and index = pthread_self() - 1. I had to subtract 1 because pthread_self starts at 1 but lwpid apparently starts with index base 0.&lt;BR /&gt;&lt;BR /&gt;Thanks again!</description>
      <pubDate>Tue, 15 Jan 2002 15:41:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-does-a-thread-get-its-own-thread-id/m-p/2644627#M833418</guid>
      <dc:creator>Todd Larchuk</dc:creator>
      <dc:date>2002-01-15T15:41:50Z</dc:date>
    </item>
    <item>
      <title>Re: How does a thread get its own thread id?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-does-a-thread-get-its-own-thread-id/m-p/2644628#M833419</link>
      <description>I'm looking for the same information that Todd is, and for the same reasons.  While the techniques detailed here are a good start, they do not seem to work reliably.&lt;BR /&gt;&lt;BR /&gt;In my application, I can call pstat_getlwp passing an index equal to (pthread_self()-1) only until a thread exits.  Once a thread exits, all further calls to pstat_getlwp fail with errno=3 (No such process).  I think this is because pthread_self() returns a number that is monotonically increasing for the given process, whereas the index required by pstat_getlwp is bounded by the number of active threads (light-weight processes) in the process.&lt;BR /&gt;&lt;BR /&gt;So, my question becomes:  How do I determine the proper index of the current thread (lwp)?</description>
      <pubDate>Wed, 31 Jul 2002 19:49:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-does-a-thread-get-its-own-thread-id/m-p/2644628#M833419</guid>
      <dc:creator>Mark Haye_2</dc:creator>
      <dc:date>2002-07-31T19:49:51Z</dc:date>
    </item>
    <item>
      <title>Re: How does a thread get its own thread id?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-does-a-thread-get-its-own-thread-id/m-p/2644629#M833420</link>
      <description>Since my previous post, I have changed my code to scan all lwp's for my pid to find the one that doesn't match the lwpid of any existing (or recently ended) threads.  That lwpid must represent the thread just created.  It is working reliably, but it seems like a lot more work than it should be.  Any better solutions out there?&lt;BR /&gt;&lt;BR /&gt;My application runs on HP-UX 11.00 and up, 32-bit and 64-bit executables.</description>
      <pubDate>Mon, 12 Aug 2002 23:01:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-does-a-thread-get-its-own-thread-id/m-p/2644629#M833420</guid>
      <dc:creator>Mark Haye_2</dc:creator>
      <dc:date>2002-08-12T23:01:19Z</dc:date>
    </item>
  </channel>
</rss>

