Boost::context模块中的callcc函数的异常处理测试
Boost::context是一款用于协程和上下文切换的C++库,其中的callcc函数可以实现协程之间的无缝切换。在使用callcc函数时,我们需要考虑异常处理的问题。下面是一个简单的示例程序,展示了如何使用callcc函数进行上下文切换,并对异常进行处理。
#include <boost/context/all.hpp>
#include <iostream>
void func(boost::context::continuation && c) {
try {
std::cout << "start" << std::endl;
c = c.resume();
std::cout << "end" << std::endl;
} catch (...) {
std::cout << "exception caught" << std::endl;
c = c.resume();
}
}
int main() {
boost::context::continuation c = boost::context::callcc(func);
std::cout << "returned