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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:26:06+00:00 2026-06-11T13:26:06+00:00

I don’t need to terminate the thread correctly, or make it respond to a

  • 0

I don’t need to terminate the thread correctly, or make it respond to a “terminate” command. I am interested in terminating the thread forcefully using pure C++11.

  • 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-11T13:26:08+00:00Added an answer on June 11, 2026 at 1:26 pm
    1. You could call std::terminate() from any thread and the thread you’re referring to will forcefully end.

    2. You could arrange for ~thread() to be executed on the object of the target thread, without a intervening join() nor detach() on that object. This will have the same effect as option 1.

    3. You could design an exception which has a destructor which throws an exception. And then arrange for the target thread to throw this exception when it is to be forcefully terminated. The tricky part on this one is getting the target thread to throw this exception.

    Options 1 and 2 don’t leak intra-process resources, but they terminate every thread.

    Option 3 will probably leak resources, but is partially cooperative in that the target thread has to agree to throw the exception.

    There is no portable way in C++11 (that I’m aware of) to non-cooperatively kill a single thread in a multi-thread program (i.e. without killing all threads). There was no motivation to design such a feature.

    A std::thread may have this member function:

    native_handle_type native_handle();
    

    You might be able to use this to call an OS-dependent function to do what you want. For example on Apple’s OS’s, this function exists and native_handle_type is a pthread_t. If you are successful, you are likely to leak resources.

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

Sidebar

Related Questions

Don't ask me why but I need to do the following: string ClassName =
Don't know a whole lot about streams. Why does the first version work using
Don't think my virtualhost is working correctly. This is what I have inside of
Don't know why this is happening, but after submitting a form via JS (using
don't know if this is possible.. I'm using sqlite3 schema: CREATE TABLE docs (id
Don't ask me why but i can't use this method because I need to
Don't need to do this right now but thinking about the future... What would
Don't want to sort the entries. using this does not preserve the order as
Don't need to go so far, just install Devexpress 11.2.5 and run the GridDemo(
don't know if the title describes anything about what I'm trying to say but

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.