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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:30:56+00:00 2026-05-20T10:30:56+00:00

While using boost::threads I have come across this interruption problem. When I do a

  • 0

While using boost::threads I have come across this interruption problem. When I do a boost::thread_interrupt from thread A on thread B, while B has interrupts disabled (boost::this_thread::disable_interrupts di), the interrupt seems to be lost.
That is to say, that if I put a boost::thread::interruption_point() after interruption has been enabled, it does not throw the boost::thread_interrupted exception.

Is this the expected behavior or am I doing something wrong?

Thanks

  • 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-20T10:30:56+00:00Added an answer on May 20, 2026 at 10:30 am

    Nothing in the documentation says that interruptions are re-triggered when thread B re-enables interruptions. I’ve tried a simple test program and can confirm the behaviour you describe.

    After re-enabling interruptions, you can check this_thread::interruption_requested() to see if there was an interruption requested while interruptions were disabled. If an interruption was indeed requested, you can throw a thread_interrupted exception yourself.

    Here’s a working program that demonstrates this:

    #include <boost/thread.hpp>
    #include <iostream>
    
    using namespace std;
    using namespace boost;
    
    void threadB()
    {
        int ticks = 0;
        this_thread::disable_interruption* disabler = 0;
        try
        {
            while (ticks < 20)
            {
                if (ticks == 5)
                {
                    cout << "Disabling interruptions\n";
                    disabler = new this_thread::disable_interruption;
                }
                if (ticks == 15)
                {
                    cout << "Re-enabling interruptions\n";
                    delete disabler;
                    if (this_thread::interruption_requested())
                    {
                        cout << "Interrupt requested while disabled\n";
                        throw thread_interrupted();
                    }
                }
                cout << "Tick " << ticks << "\n";
                thread::sleep(get_system_time() + posix_time::milliseconds(100));
                ++ticks;
            }
        }
        catch (thread_interrupted)
        {
            cout << "Interrupted\n";
        }
    }
    
    int main()
    {
        thread b(&threadB);
        thread::sleep(get_system_time() + posix_time::milliseconds(1000));
        b.interrupt();
        cout << "main -> Interrupt!\n";
        b.join();
    }
    

    Hope this helps.

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

Sidebar

Related Questions

I have a thread pool that is using shared mutexes from the boost library.
Unlike this question: Linker Error while building application using Boost Asio in Visual Studio
I'm having a weird problem with a threaded class using Boost::threads. Here is a
I have a problem with the following code: #include <boost/thread/thread.hpp> #include <boost/thread/mutex.hpp> #include <iostream>
I'm using an object to start boost thread and it has some public member
I am experiencing a crash while using the Boost.Spirit and Boost.Thread libraries in my
I have a question about boost::shared_ptr<T> . There are lots of thread. using namespace
I stuck while trying to compile qpid c++ with boost 1_47_0 using Visual Studio
While using regex to help solve a problem in the Python Challenge , I
I am using the timed_wait from boost C++ library and I am getting a

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.