Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building Boost.Thread without interruption

How can I build boost.thread without default interruption point. I think that my application crash in a predefined interruption points. I'm using boost 1.53.0 with msvc10

I've the following code

class IOController {
public:
    IOController() { mThread = boost::thread( boost::bind( &IOController::poll, this ) ); }
    ~IOController() {mThread.interrupt(); mThread.join() }

    void doA() { boost::lock_guard<boost::mutex> lock( mMutex);  }

private:
    void ICanThrow()
    {
        try
        {
            boost::lock_guard<boost::mutex> lock( mMutex); 
            callFunctionWithSleepFor(); // calling function that can throw and use boost::sleep_for
        }
        catch( boost::system_error&) {}
        catch( std::exception& ) {}
        catch ( ... ) { /* APPLICATION CRASH. */ }
    }
    // this is a thread: mThread = boost::thread(&IOController::poll, this) on ctor
    void poll()
    {
        while(true)
        {
            callFunctionWithSleepFor( );            
            this_thread::sleep_for( some_time );
        }
    }
boost::mutex mMutex;
boost::thread mThread;
};

Now I've the main thread that is calling that is calling doA in a very intensive way, and the class is polling on another thread. But sometimes I caght an exception in ICanThrow in the catch (...). I've no idea why this happen. But happen always from poll() thread.

Now I want try to build Boost without DONT_PROVIDE_INTERRUPTIONS. Does someone have some suggest?

like image 830
Elvis Dukaj Avatar asked Apr 30 '26 00:04

Elvis Dukaj


1 Answers

Maybe have a look at http://www.boost.org/doc/libs/1_35_0/doc/html/thread/thread_management.html. You can disable thread interruption with the disable_interruption class. I haven't used it myself, but it looks like if you instantiate disable_interruption, interruptions should be disabled until the disable_interruption object goes out of scope.

like image 173
Arno Duvenhage Avatar answered May 02 '26 14:05

Arno Duvenhage



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!