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

  • Home
  • SEARCH
  • 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 878319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:45:09+00:00 2026-05-15T11:45:09+00:00

I have a thread datatype in the interpreter implementation for a programming language I

  • 0

I have a thread datatype in the interpreter implementation for a programming language I am working on. For various reasons, it’s a fairly common operation, to need to get the current thread (which is, itself, a pointer: a struct thread*).

However, pthread_self(3) hands me a pthread_t, which is an opaque type; on some systems, it seems to be an unsigned long, but I hear I can’t depend on that being the case. I suspect a hash table is the proper implementation of this unique mapping (pthread_t ID to struct thread pointer); however, I have no idea how to hash the pthread_t reliably.

I would appreciate advice from anybody with more experience with pthread(3) or, really, any situation wherein you have to “hash” an opaque datatype.

  • 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-15T11:45:10+00:00Added an answer on May 15, 2026 at 11:45 am

    I think the best way to hold your struct thread* is thread-local storage. Something like:

    static pthread_key_t struct_thread_key;
    pthread_key_create(&struct_thread_key, NULL);
    

    In the thread initalizer:

    struct thread *my_thread = malloc(sizeof(*my_thread));
    // ...
    pthread_setspecific(struct_thread_key, my_thread);
    

    To access the current thread later:

    struct thread *my_thread = (struct thread *) pthread_getspecific(struct_thread_key);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thread where downloading xml file a this xml file i want to
Suppose I have thread 1, the main window UI thread and thread 2, a
Is if almost always required to have thread syncing (i.e. use of mutex, semaphores,
I have a thread which needs to be run in the background every 1000ms.
I have a thread from a thread pool in a service that does quite
I have some thread to write resource and some to read it.But pthread_rwlock cause
I have several thread pools and I want my application to handle a cancel
I have a thread in Ruby. It runs a loop. When that loop reaches
I have a thread running in the background. How do i send it messages
I have a thread that does the following: 1) Do some work 2) Wait

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.