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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:11:57+00:00 2026-05-15T18:11:57+00:00

I’ve been playing around with boost threads today as a learning exercise, and I’ve

  • 0

I’ve been “playing around with” boost threads today as a learning exercise, and I’ve got a working example I built quite a few months ago (before I was interrupted and had to drop multi-threading for a while) that’s showing unusual behaviour.

When I initially wrote it I was using MingW gcc 3.4.5, and it worked. Now I’m using 4.4.0 and it doesn’t – incidentally, I’ve tried again using 3.4.5 (I kept that version it a separate folder when I installed 4.4.0) and it’s still working.

The code is at the end of the question; in summary what it does is start two Counter objects off in two child threads (these objects simply increment a variable then sleep for a bit and repeat ad infinitum – they count), the main thread waits for the user via a cin.get() and then interrupts both threads, waits for them to join, then outputs the result of both counters.

Complied with 3.4.5 it runs as expected.

Complied with 4.4.0 it runs until the user input, then dies with a message like the below – it seems the the interrupt exceptions are killing the entire process?

terminate called after throwing an instance of ‘
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application’s support team for more information.
boost::thread_interrupted’

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application’s support team for more information.

From what I read, I think that any (?) uncaught exception that is allowed to propagate out of a child thread will kill the process? But, I’m catching the interrupts here, aren’t I? At least I seem to be when using 3.4.5.

So, firstly, have I understood how interrupting works?
And, any suggestions as to what is happening and how to fix?

Code:

#include <iostream>
#include <boost/thread/thread.hpp>
#include <boost/date_time.hpp>

//fixes a linker error for boost threads in 4.4.0 (not needed for 3.4.5)
//found via Google, so not sure on validity - but does fix the link error.
extern "C" void tss_cleanup_implemented() { }

class CCounter
{
private:
    int& numberRef;
    int  step;
public:
    CCounter(int& number,int setStep) : numberRef(number) ,step(setStep) { }

    void operator()()
    {
        try
        {
            while( true )
            {
                boost::posix_time::milliseconds pauseTime(50);
                numberRef += step;
                boost::this_thread::sleep(pauseTime);
            }
        }
        catch( boost::thread_interrupted const& e )
        {
            return;
        }
    }
};

int main( int argc , char *argv[] )
{
    try
    {
        std::cout << "Starting counters in secondary threads.\n";

        int number0 = 0,
            number1 = 0;
        CCounter counter0(number0,1);
        CCounter counter1(number1,-1);

        boost::thread threadObj0(counter0);
        boost::thread threadObj1(counter1);

        std::cout << "Press enter to stop the counters:\n";
        std::cin.get();

        threadObj0.interrupt();
        threadObj1.interrupt();

        threadObj0.join();
        threadObj1.join();

        std::cout << "Counter stopped. Values:\n"
                  << number0 << '\n'
                  << number1 << '\n';
    }
    catch( boost::thread_interrupted& e )
    {
        std::cout << "\nThread Interrupted Exception caught.\n";
    }
    catch( std::exception& e )
    {
        std::cout << "\nstd::exception thrown.\n";
    }
    catch(...)
    {
        std::cout << "\nUnexpected exception thrown.\n"
    }

    return EXIT_SUCCESS;
}
  • 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-15T18:11:57+00:00Added an answer on May 15, 2026 at 6:11 pm

    Solved.

    It turns out adding the complier flag -static-libgcc removes the problem with 4.4.0 (and has no apparent affect with 3.4.5) – or at least in this case the program returns the expected results.

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

Sidebar

Ask A Question

Stats

  • Questions 463k
  • Answers 463k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try this: SELECT T1.products_bought, COUNT(T2.cnt) AS total FROM ( SELECT… May 16, 2026 at 12:49 am
  • Editorial Team
    Editorial Team added an answer You can not specify negative value to LIMIT clause: LIMIT… May 16, 2026 at 12:49 am
  • Editorial Team
    Editorial Team added an answer To do screenshots in Selenium 2 you need to do… May 16, 2026 at 12:49 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.