Boost.Coroutine不使用分段堆栈 [英] Boost.Coroutine not using segmented stacks

查看:147
本文介绍了Boost.Coroutine不使用分段堆栈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能给我一个例子,说明如何使用带有增强协程的分段堆栈?我是否必须使用特殊的split-stack属性注释从协程调用的每个函数?

Can anyone give me an example of how I can use segmented stacks with boost coroutines? Do I have to annotate every function that is called from the coroutine with a special split-stack attribute?

当我尝试编写一个应该使用分段堆栈的程序时,它只会出现段错误.

When I try and write a program that should use segmented stacks, it just segfaults.

这是我到目前为止所做的 https://wandbox.org/permlink/TltQwGpy4hRoHgDY 如果分段堆栈,该代码似乎很快会出现段错误如果使用,我希望它能够处理更多的迭代.该程序在35次迭代后出错.

Here is what I have done so far https://wandbox.org/permlink/TltQwGpy4hRoHgDY The code seems to segfault very quickly, if segmented stacks were used I would expect it to be able to handle more iterations. The program errors out after 35 iterations.

#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

Compiling that code with -fsplit-stack solves the problem. Annotations are not required. All functions are by default treated as split stacks. Example - https://wandbox.org/permlink/Pzzj5gMoUAyU0h7Q

那样容易.

这篇关于Boost.Coroutine不使用分段堆栈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆