Commit e3d6a79a authored by Xavier Thompson's avatar Xavier Thompson

Add test program with fork helper

parent c8934bf3
#include <task.hpp>
#include <fork.hpp>
#include <join.hpp>
#include <root.hpp>
#include <cstdio>
using namespace typon::rt;
int fibo(int n) {
if (n < 2)
return n;
return fibo(n - 1) + fibo(n - 2);
}
template <typename T>
Fork<T> fork(Task<T> task)
{
co_return co_await std::move(task);
}
Task<void> hello(int i) {
int n = fibo(10);
(void) i;
(void) n;
printf("hello from %d on %u, fibo(40) = %d\n", i, Scheduler::thread_id, n);
co_return;
}
Join<void> parallel() {
for (int i = 0; i < 30; i++) {
co_await fork(hello(i));
printf("parallel resumed on %u\n", Scheduler::thread_id);
}
printf("parallel syncing on %u\n", Scheduler::thread_id);
co_await Sync();
printf("parallel resumed on %u\n", Scheduler::thread_id);
for (int i = 30; i < 60; i++) {
co_await fork(hello(i));
printf("parallel resumed on %u\n", Scheduler::thread_id);
}
}
Root root() {
co_await parallel();
printf("root resumed on %u\n", Scheduler::thread_id);
}
int main() {
root().call();
puts("done");
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment