谁能给我一个示例,说明如何将分段堆栈与 boost 协程一起使用?split-stack
我是否必须用特殊属性 注释从协程调用的每个函数?
当我尝试编写一个应该使用分段堆栈的程序时,它只是段错误。
这是我到目前为止所做 的事情https://wandbox.org/permlink/TltQwGpy4hRoHgDY 代码似乎很快就会出现段错误,如果使用分段堆栈,我希望它能够处理更多迭代。程序在 35 次迭代后出错。
#include <boost/coroutine2/all.hpp>
#include <iostream>
#include <array>
using std::cout;
using std::endl;
class Int {
int a{2};
};
void foo(int num) {
cout << "In iteration " << num << endl;
std::array<Int, 1000> arr;
static_cast<void>(arr);
foo(num + 1);
}
int main() {
using Coroutine_t = boost::coroutines2::coroutine<int>::push_type;
auto coro = Coroutine_t{[&](auto& yield) {
foo(yield.get());
}};
coro(0);
}