【发布时间】:2021-10-13 18:45:39
【问题描述】:
我想知道当在多个线程的 io_context 上使用 boost asio 的 run() 函数时,在处理函数中引发异常时会发生什么。我在 io_context 上调用 run 操作的线程函数如下所示:
while(!io->stopped() && *stop == false) {
try {
auto cnt = io->run();
}catch(std::exception &e) {
}
if(io->stopped()) {
break;
}
}
线程数为 1..N。该文档指出,对 run() 的任何后续调用都必须首先调用 restart() ,但是当仍然有任何对 run() 的活动调用时,不得调用 restart() ,我不知道,因为可能仍有线程调用 run ()。
当只有一个 io_context 和多个线程调用 run() 时,解决办法是什么
【问题讨论】:
标签: c++ boost-asio