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 8825609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:55:16+00:00 2026-06-14T06:55:16+00:00

If I have a std::thread object t , I can use t.native_handle() to get

  • 0

If I have a std::thread object t, I can use t.native_handle() to get access to the API of the underlying thread implementation (e.g., pthreads or Windows threads). But what if I have a handle from the underlying thread implementation (e.g., a pthreads thread). Is there any way to transform that into a C++11 std::thread?

The motivation for this is that it might be desirable to use the native platform threading API to set up a thread with, e.g., a particular affinity or a particular stack size (or some other characteristic that is not accessible via the C++11 API). From that point forward, however, it’d be nice to stick to the C++11 functionality.

Is there any way to do this?

  • 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-06-14T06:55:18+00:00Added an answer on June 14, 2026 at 6:55 am

    With GCC you can construct a std::thread::id from a std::thread::native_handle_type but you cannot construct a std::thread from it.

    This means you can test whether a given pthread_t refers to the same thread as a std::thread object (or to this_thread::get_id()) but you cannot create new thread objects from it.

    A std::thread is designed to be a unique handle to a thread. The only way for a different thread object to take ownership of the underlying thread is by moving it from the original, so only one object “owns” it at once. If you could construct them from a native handle you could do:

    // start new thread
    std::thread t(&thread_func);
    
    // now have two handles to the same thread
    std::thread t2( t.native_handle() );
    
    std::thread t1.join();
    
    // erm, hang on, this isn't right
    std::thread t2.join();
    

    The motivation for this is that it might be desirable to use the native platform threading API to set up a thread with, e.g., a particular affinity or a particular stack size (or some other characteristic that is not accessible via the C++11 API).

    Ideally the platform would allow you to specify parameters such as affinity or stacksize when you construct the thread, which would allow you to use those platform-specific features without weakening the type system by constructing “non-owning” thread objects… but at least GCC doesn’t support doing that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a std::map that is used by multiple threads to store data. The
Can anyone point me to a thread-safe implementation of the Copy-on-write (COW) idiom? The
I have std::list<Info> infoList in my application that is shared between two threads. These
let's say I have std::map< std::string, std::string > m_someMap as a private member variable
I have a std::vector of some class of the form class A{ public: A():i(someNumber){}
I have declared std::priority_queue like this. priority_queue < Aircraft, vector<Aircraft>, less<Aircraft> > *q; And
I have an std::vector of handle objects. I have to wait on these handle
I have an std::vector that holds all the objects and is passed to them
I have typedef std::string OrderID; I would like to overload the operator ++ for
I have a std::map<std::string, HANDLE> SampleMap which stores HANDLE objects as value. After the

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.