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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:26:01+00:00 2026-05-18T20:26:01+00:00

With the C++0x feature of exception_ptr one can store an exception in one thread

  • 0

With the C++0x feature of exception_ptr one can store an exception in one thread and have another thread access it. However, the other thread has to call rethrow_exception(). In some cases, however, I need to actually interrupt the other thread and have the exception be raised there immediately; polling the exception_ptr for non-null is not a solution.

I found a solution for how to inject an exception in Windows at http://www.codeproject.com/KB/exception/ExcInject.aspx by suspending a thread and modifying its instruction pointer register before resuming it. However, I also need my code to run on Linux. How do I accomplish it there?

If I use something like getcontext(), that gets the current thread’s context (whereas in Windows, GetContext() accepts a thread parameter), so I would have to call it in a signal handler. But I’ve read that getcontext()/setcontext() should not be called in signal handlers…
Alternatively, I could call rethrow_exception() directly in the signal handler, but I’m worried this won’t have the intended effect, where the interrupted thread has the stack unwound in the same way with all destructors of the scope the interruption was in called etc.

  • 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-18T20:26:01+00:00Added an answer on May 18, 2026 at 8:26 pm

    I read that article you linked to some time ago, and I was a bit skeptical.

    The approach of modifying another thread’s instruction pointer directly feels VERY scary. You have absolutely no idea what operation you’re interrupting and leaving half-completed, and the interrupted operation may not be expecting an exception and thus have no ability to clean up after itself.

    On Windows, I’ve used QueueUserAPC successfully to abort other threads once they enter an alertable wait state. I don’t know of any direct equivalent for this in Linux.

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

Sidebar

Related Questions

A feature in Eclipse that I really miss is how you can auto-complete method
Windows has a feature that allows an administrator to perform auto-logon whenever it is
One of the feature requests I've got for the program I'm working on is
The Exception class in Delphi 2009 received a number of new features. A number
A feature of C++ is the ability to create unnamed (anonymous) namespaces, like so:
Anyone know this compiler feature? It seems GCC support that. How does it work?
I sometimes use the feature 'Reconcile Offline Work...' found in Perforce's P4V IDE to
When using feature descriptors [like SIFT, SURF] - is Approximate Nearest Neighbour the fastest
ReSharper Code cleanup feature (with reorder members and reformat code enabled) is really great.
Trying to honor a feature request from our customers, I'd like that my application,

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.