【发布时间】:2020-07-08 12:47:03
【问题描述】:
我正在运行一个boost::thread,它被我程序中的其他地方中断了。
auto my_thread = boost::thread(&threadedFunction, this);
像这样使用function-try-block
void threadedFunction() try {
// do stuff
} catch (boost::thread_interrupted &) {
// handle error
}
相当于使用包含整个函数的 try-catch 块?
void threadedFunction() {
try {
// do stuff
} catch (boost::thread_interrupted &) {
// handle error
}
}
它们可能不等价,因为my_thread 可以在进入try 块之前被中断,在这种情况下,程序会崩溃。话虽如此,我不确定这是否可能。
两个代码块是否等效?
【问题讨论】:
标签: multithreading c++11 exception boost try-catch