Как я могу построить boost.thread без точки прерывания по умолчанию. Я думаю, что мое приложение вылетает в предопределенных точках прерывания. Я использую boost 1.53.0 с msvc10.
У меня есть следующий код
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;
};
Теперь у меня есть основной поток, который вызывает doA очень интенсивно, а класс опрашивает другой поток. Но иногда я ловил исключение в ICanThrow в улове (...). Я понятия не имею, почему это происходит. Но всегда происходит из потока poll().
Теперь я хочу попробовать собрать Boost без DONT_PROVIDE_INTERRUPTIONS. Есть ли у кого-то предложения?
boost::thread_interrupted
является производным отstd::exception
. Вы можете использовать средствоdisable_interruption
для отключения прерываний текущего потока: boost.org/doc/libs/1_53_0/doc/html/thread/ - person Igor R.   schedule 26.04.2013