pthread_self... - Redhat

This is a discussion on pthread_self... - Redhat ; Hi, I realized with surprise that with Red Hat Linux pthread id is almost always a huge number, usually 8-9 digits decimal. Why is that so? Can I reset it at a start point of a process so that like ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: pthread_self...

  1. pthread_self...

    Hi,

    I realized with surprise that with Red Hat Linux pthread
    id is almost always a huge number, usually 8-9 digits
    decimal. Why is that so? Can I reset it at a start point
    of a process so that like in "regular Unix" flavors the
    tid will begin at 0 or 1?

    Thomas

  2. Re: pthread_self...

    ThomasH writes:
    >Hi,
    >
    >I realized with surprise that with Red Hat Linux pthread
    >id is almost always a huge number, usually 8-9 digits
    >decimal. Why is that so? Can I reset it at a start point
    >of a process so that like in "regular Unix" flavors the
    >tid will begin at 0 or 1?
    >
    >Thomas


    No.

    Why do you care what the TID is? The TID is intended by
    POSIX to be completely opaque to the application.

    scott

  3. Re: pthread_self...

    Scott Lurndal wrote:
    >
    > ThomasH writes:
    > >Hi,
    > >
    > >I realized with surprise that with Red Hat Linux pthread
    > >id is almost always a huge number, usually 8-9 digits
    > >decimal. Why is that so? Can I reset it at a start point
    > >of a process so that like in "regular Unix" flavors the
    > >tid will begin at 0 or 1?
    > >
    > >Thomas

    >
    > No.
    >
    > Why do you care what the TID is? The TID is intended by
    > POSIX to be completely opaque to the application.
    >
    > scott


    They are in fact used quite often to identify the originator
    of events in wide sense of this term. For example, if your
    application starts some 20 threads in the same order, you might
    known that hypothetically "thread 14" is the heartbit-listener
    or whatever.

    Anyway, its not a big issue, this can be resolved by a small
    wrapper. I was hoping that we could avoid making it.

    Thomas

  4. Re: pthread_self...

    ThomasH writes:
    >Scott Lurndal wrote:
    >>


    >>
    >> Why do you care what the TID is? The TID is intended by
    >> POSIX to be completely opaque to the application.
    >>
    >> scott

    >
    >They are in fact used quite often to identify the originator
    >of events in wide sense of this term. For example, if your
    >application starts some 20 threads in the same order, you might
    >known that hypothetically "thread 14" is the heartbit-listener
    >or whatever.


    The proper way to do this is to use pthread_key_create and
    create a per-thread data item containing per-thread identification
    information (like some human readable name "listenerthread_1",
    "process_thread_6", "heartbeat-listener").

    Having random TID's makes certain programmatic bugs more
    easily detected.

    What happens to your program if Solaris, or HP-UX or
    whatever other unix implementation you are using changes
    the way they assign TID's? There's no guarantee that
    they won't.

    scott

    >
    >Anyway, its not a big issue, this can be resolved by a small
    >wrapper. I was hoping that we could avoid making it.
    >
    >Thomas


  5. Re: pthread_self...

    Scott Lurndal wrote:
    >
    > ThomasH writes:
    > >Scott Lurndal wrote:
    > >>
    > >> Why do you care what the TID is? The TID is intended by
    > >> POSIX to be completely opaque to the application.
    > >>
    > >> scott

    > >
    > >They are in fact used quite often to identify the originator
    > >of events in wide sense of this term. For example, if your
    > >application starts some 20 threads in the same order, you might
    > >known that hypothetically "thread 14" is the heartbit-listener
    > >or whatever.

    >
    > The proper way to do this is to use pthread_key_create and
    > create a per-thread data item containing per-thread identification
    > information (like some human readable name "listenerthread_1",
    > "process_thread_6", "heartbeat-listener").


    Good idea! Thanks.

    Thomas

    >
    > Having random TID's makes certain programmatic bugs more
    > easily detected.
    >
    > What happens to your program if Solaris, or HP-UX or
    > whatever other unix implementation you are using changes
    > the way they assign TID's? There's no guarantee that
    > they won't.
    >
    > scott
    >
    > >
    > >Anyway, its not a big issue, this can be resolved by a small
    > >wrapper. I was hoping that we could avoid making it.
    > >
    > >Thomas


+ Reply to Thread