Commit f72c7dbc authored by Xavier Thompson's avatar Xavier Thompson

Adapt test programs and improve exception.cpp

parent e63b38af
#include <typon/fork.hpp>
#include <typon/join.hpp>
#include <typon/root.hpp>
#include <typon/typon.hpp>
#include <cstdio>
......@@ -13,21 +11,25 @@ int fibo(int n) {
return fibo(n - 1) + fibo(n - 2);
}
Fork<int> fib() {
Task<int> fib() {
co_return fibo(30);
}
Fork<void> fail() {
Task<void> fail() {
throw std::exception();
co_return;
}
Join<void> fail_join() {
co_await fork(fail());
}
Join<void> join(int max) {
std::vector<Future<Fork<int>::promise_type>> v;
std::vector<Future<core::Fork<int>::promise_type>> v;
for (int i = 0; i < max; i++) {
v.push_back(co_await fib());
v.push_back(co_await fork(fib()));
}
co_await fail();
co_await fork(fail_join());
co_await Sync();
for (auto & f : v) {
printf("result = %d\n", f.get());
......
#include <typon/task.hpp>
#include <typon/core/task.hpp>
#include <cstdio>
using namespace typon;
using namespace typon::core;
Task<int> fibo(int n) {
if (n < 2) {
......
#include <typon/task.hpp>
#include <typon/fork.hpp>
#include <typon/join.hpp>
#include <typon/root.hpp>
#include <typon/typon.hpp>
#include <cstdio>
......@@ -13,12 +10,6 @@ int fibo(int 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;
......
#include <typon/fork.hpp>
#include <typon/join.hpp>
#include <typon/root.hpp>
#include <typon/typon.hpp>
#include <cstdio>
......@@ -12,36 +10,36 @@ int fibo(int n) {
return fibo(n - 1) + fibo(n - 2);
}
Fork<void> hello(int i) {
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);
printf("hello from %d on %u, fibo(40) = %d\n", i, core::Scheduler::thread_id, n);
// printf("hello from %d on %lu, fibo(40) = %d\n", i, riften::detail::static_id, n);
co_return;
}
Join<void> parallel() {
for (int i = 0; i < 30; i++) {
co_await hello(i);
printf("parallel resumed on %u\n", Scheduler::thread_id);
co_await fork(hello(i));
printf("parallel resumed on %u\n", core::Scheduler::thread_id);
// printf("parallel resumed on %lu\n", riften::detail::static_id);
}
printf("parallel syncing on %u\n", Scheduler::thread_id);
printf("parallel syncing on %u\n", core::Scheduler::thread_id);
// printf("parallel syncing on %lu\n", riften::detail::static_id);
co_await Sync();
printf("parallel resumed on %u\n", Scheduler::thread_id);
printf("parallel resumed on %u\n", core::Scheduler::thread_id);
// printf("parallel resumed on %lu\n", riften::detail::static_id);
for (int i = 30; i < 60; i++) {
co_await hello(i);
printf("parallel resumed on %u\n", Scheduler::thread_id);
co_await fork(hello(i));
printf("parallel resumed on %u\n", core::Scheduler::thread_id);
// printf("parallel resumed on %lu\n", riften::detail::static_id);
}
}
Root root() {
co_await parallel();
printf("root resumed on %u\n", Scheduler::thread_id);
printf("root resumed on %u\n", core::Scheduler::thread_id);
}
int main() {
......
#include <typon/root.hpp>
#include <typon/join.hpp>
#include <typon/fork.hpp>
#include <typon/typon.hpp>
#include <cstdio>
using namespace typon;
Join<int> fibo(int n);
Fork<int> fork_fibo(int n);
Join<int> fibo(int n) {
if (n < 2) {
co_return n;
}
Future a = co_await fork_fibo(n - 1);
Future b = co_await fork_fibo(n - 2);
core::Future a = co_await fork(fibo(n - 1));
core::Future b = co_await fork(fibo(n - 2));
co_await Sync();
co_return a.get() + b.get();
}
Fork<int> fork_fibo(int n) {
co_return co_await fibo(n);
}
Root root() {
int result = co_await fibo(40);
printf("%d\n", result);
......
#include <typon/fork.hpp>
#include <typon/join.hpp>
#include <typon/root.hpp>
#include <typon/task.hpp>
#include <typon/typon.hpp>
#include <cstdio>
......@@ -16,9 +13,6 @@ int fibo(int n) {
return a + b;
}
Join<int> parallel_fibo(int n);
Fork<int> fork_fibo(int n);
Join<int> parallel_fibo(int n) {
if (n < 2) {
co_return n;
......@@ -29,16 +23,12 @@ Join<int> parallel_fibo(int n) {
int b = fibo(n - 2);
co_return a + b;
}
Future a = co_await fork_fibo(n - 1);
Future b = co_await fork_fibo(n - 2);
auto a = co_await fork(parallel_fibo(n - 1));
auto b = co_await fork(parallel_fibo(n - 2));
co_await Sync();
co_return a.get() + b.get();
}
Fork<int> fork_fibo(int n) {
co_return co_await parallel_fibo(n);
}
Root root() {
int result = co_await parallel_fibo(40);
printf("%d\n", result);
......
#include <typon/task.hpp>
#include <typon/core/task.hpp>
#include <cstdio>
using namespace typon;
using namespace typon::core;
Task<int> add(int a, int b) {
co_return a + b;
......
#include <typon/task.hpp>
#include <typon/core/task.hpp>
#include <cstdio>
using namespace typon;
using namespace typon::core;
Task<int> fibo(int n) {
if (n < 2) {
......
#include <typon/fork.hpp>
#include <typon/join.hpp>
#include <typon/root.hpp>
#include <typon/task.hpp>
#include <typon/typon.hpp>
#include <cstdio>
......@@ -17,9 +14,6 @@ Task<int> fibo(int n) {
co_return a + b;
}
Join<int> parallel_fibo(int n);
Fork<int> fork_fibo(int n);
Join<int> parallel_fibo(int n) {
// printf("parallel_fibo(%d)\n", n);
if (n < 2) {
......@@ -32,16 +26,12 @@ Join<int> parallel_fibo(int n) {
// printf("// parallel_fibo(%d)\n", n);
co_return a + b;
}
Future a = co_await fork_fibo(n - 1);
Future b = co_await fork_fibo(n - 2);
auto a = co_await fork(parallel_fibo(n - 1));
auto b = co_await fork(parallel_fibo(n - 2));
co_await Sync();
co_return a.get() + b.get();
}
Fork<int> fork_fibo(int n) {
co_return co_await parallel_fibo(n);
}
Root root() {
int result = co_await parallel_fibo(40);
printf("result = %d\n", result);
......
#include <typon/fork.hpp>
#include <typon/join.hpp>
#include <typon/root.hpp>
#include <typon/typon.hpp>
#include <cstdio>
using namespace typon;
Root root() {
printf("root resumed on %u\n", Scheduler::thread_id);
printf("root resumed on %u\n", core::Scheduler::thread_id);
co_return;
}
......
#include <typon/task.hpp>
#include <typon/core/task.hpp>
#include <cstdio>
using namespace typon;
using namespace typon::core;
Task<int> add(int a, int b) {
printf("add(%d, %d)\n", a, b);
......
#include <typon/task.hpp>
#include <typon/core/task.hpp>
#include <cstdio>
using namespace typon;
using namespace typon::core;
Task<int> add(int a, int b) {
co_return a + b;
......
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