谁能给我一个例子,说明如何将分段堆栈与 boost 协程一起使用?我是否必须使用特殊的注释来注释从协程调用的每个函数split-stack
属性?
当我尝试编写一个程序时should使用分段堆栈,它只会出现段错误。
这是我到目前为止所做的https://wandbox.org/permlink/TltQwGpy4hRoHgDY 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);
}
编译该代码-fsplit-stack
解决问题。不需要注释。默认情况下,所有函数都被视为拆分堆栈。例子 -https://wandbox.org/permlink/Pzzj5gMoUAyU0h7Q https://wandbox.org/permlink/Pzzj5gMoUAyU0h7Q
就这么简单。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)