Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 468257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:39:50+00:00 2026-05-12T23:39:50+00:00

Searched, but don’t come across a satisfying answer. I know there’s no a portable

  • 0

Searched, but don’t come across a satisfying answer.

I know there’s no a portable way to print a pthread_t.

How do you do it in your app?

Update:

Actually I don’t need pthread_t, but some small numeric id, identifying in debug message different threads.

On my system (64 bit RHEL 5.3) it’s defined as unsigned long int, so it’s big number and just printing it eats a valuable place in debug line. How does gdb assign short tids?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T23:39:50+00:00Added an answer on May 12, 2026 at 11:39 pm

    This will print out a hexadecimal representation of a pthread_t, no matter what that actually is:

    void fprintPt(FILE *f, pthread_t pt) {
      unsigned char *ptc = (unsigned char*)(void*)(&pt);
      fprintf(f, "0x");
      for (size_t i=0; i<sizeof(pt); i++) {
        fprintf(f, "%02x", (unsigned)(ptc[i]));
      }
    }
    

    To just print a small id for a each pthread_t something like this could be used (this time using iostreams):

    void printPt(std::ostream &strm, pthread_t pt) {
      static int nextindex = 0;
      static std::map<pthread_t, int> ids;
      if (ids.find(pt) == ids.end()) {
        ids[pt] = nextindex++;
      }
      strm << ids[pt];
    }
    

    Depending on the platform and the actual representation of pthread_t it might here be necessary to define an operator< for pthread_t, because std::map needs an ordering on the elements:

    bool operator<(const pthread_t &left, const pthread_t &right) {
      ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have searched everywhere but I couldn't find my answer, is there a way
I've searched for this question but I don't know if I've phrased it correctly.
I've searched around but I don't really know how to interpret the wadl file
I've searched around, but don't think I really found an answer. I'm trying to
I searched but couldn't find anything what I can print and put on the
I've searched but cannot find the answer to When to use them. I just
I have searched but have not found my answer. Disclaimer: I am brand new
I had an confusion of which I searched but didn't get any answer. I
I have searched everywhere but just can't seem to find the answer. Can you
I've searched for an example of sorting a DataGridView on multiple columns, but don't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.