2021-11-01 17:59:08 +08:00
|
|
|
|
|
2017-09-24 14:01:30 +08:00
|
|
|
|
#include <chrono>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
2021-11-01 17:59:08 +08:00
|
|
|
|
#include "librf/librf.h"
|
2017-09-24 14:01:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const int M = 10;
|
|
|
|
|
|
|
|
|
|
size_t dynamic_go_count = 0;
|
|
|
|
|
std::array<std::array<std::array<int32_t, M>, M>, 3> dynamic_cells;
|
|
|
|
|
|
|
|
|
|
void test_dynamic_go()
|
|
|
|
|
{
|
2021-11-01 17:59:08 +08:00
|
|
|
|
auto co_star = [](int j) -> librf::future_t<int>
|
2017-09-24 14:01:30 +08:00
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < M; ++i)
|
|
|
|
|
{
|
2021-11-01 17:59:08 +08:00
|
|
|
|
go[=]() -> librf::generator_t<int>
|
2017-09-24 14:01:30 +08:00
|
|
|
|
{
|
|
|
|
|
for (int k = 0; k < M; ++k)
|
|
|
|
|
{
|
|
|
|
|
++dynamic_cells[j][i][k];
|
|
|
|
|
++dynamic_go_count;
|
|
|
|
|
|
|
|
|
|
std::cout << j << " " << i << " " << k << std::endl;
|
|
|
|
|
co_yield k;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
co_return M;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
co_yield i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
co_return M;
|
|
|
|
|
};
|
|
|
|
|
go co_star(0);
|
|
|
|
|
go co_star(1);
|
|
|
|
|
go co_star(2);
|
|
|
|
|
|
2021-11-01 17:59:08 +08:00
|
|
|
|
librf::this_scheduler()->run_until_notask();
|
2017-09-24 14:01:30 +08:00
|
|
|
|
|
|
|
|
|
std::cout << "dynamic_go_count = " << dynamic_go_count << std::endl;
|
|
|
|
|
for (auto & j : dynamic_cells)
|
|
|
|
|
{
|
|
|
|
|
for (auto & i : j)
|
|
|
|
|
{
|
|
|
|
|
for (auto k : i)
|
|
|
|
|
std::cout << k;
|
|
|
|
|
std::cout << std::endl;
|
|
|
|
|
}
|
|
|
|
|
std::cout << std::endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void resumable_main_dynamic_go()
|
|
|
|
|
{
|
|
|
|
|
test_dynamic_go();
|
|
|
|
|
}
|
2020-09-23 22:56:51 +08:00
|
|
|
|
|
2021-11-02 17:15:17 +08:00
|
|
|
|
#if LIBRF_TUTORIAL_STAND_ALONE
|
2020-09-23 22:56:51 +08:00
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
resumable_main_dynamic_go();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2021-11-02 17:15:17 +08:00
|
|
|
|
#endif
|