簡體   English   中英

Boost.Coroutine不使用分段堆棧

[英]Boost.Coroutine not using segmented stacks

任何人都可以給我一個例子,說明我如何使用分段堆棧和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);
}

使用-fsplit-stack編譯該代碼可以解決問題。 注釋不是必需的。 默認情況下,所有函數都被視為拆分堆棧。 示例 - https://wandbox.org/permlink/Pzzj5gMoUAyU0h7Q

很簡單。

使用b2屬性segmented-stacks = on編譯boost(boost.context和boost.coroutine)(在boost.coroutine和boost.context中啟用特殊代碼)。

您的應用必須使用-DBOOST_USE_SEGMENTED_STACKS-fsplit-stack (boost.coroutines標頭所需)進行編譯。

請參閱文檔: http//www.boost.org/doc/libs/1_65_1/libs/coroutine/doc/html/coroutine/stack/segmented_stack_allocator.html

boost.coroutine包含一個演示分段堆棧的示例(在目錄coroutine / example / asymmetric / call b2 toolset=gcc segmented-stacks=on )。

請注意:雖然llvm支持分段堆棧,但clang接縫不提供__splitstack_<xyz>函數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM