Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
typon
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
cython-plus
typon
Commits
da6a75a1
Commit
da6a75a1
authored
Jun 03, 2022
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add future.cpp test program
parent
2f37b314
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
0 deletions
+42
-0
rt/test/future.cpp
rt/test/future.cpp
+42
-0
No files found.
rt/test/future.cpp
0 → 100644
View file @
da6a75a1
#include <typon/typon.hpp>
#include <cstdio>
using
namespace
typon
;
int
fibo
(
int
n
)
{
if
(
n
<
2
)
return
n
;
return
fibo
(
n
-
1
)
+
fibo
(
n
-
2
);
}
Task
<
void
>
consume
(
Future
<
int
>
&
f
)
{
printf
(
"[%u] waiting on future
\n
"
,
Scheduler
::
thread_id
);
int
value
=
co_await
f
;
printf
(
"[%u] future yielded %d
\n
"
,
Scheduler
::
thread_id
,
value
);
}
Task
<
void
>
produce
(
Future
<
int
>
&
f
,
int
n
)
{
int
value
=
fibo
(
n
);
printf
(
"[%u] producing %d
\n
"
,
Scheduler
::
thread_id
,
value
);
f
.
put
(
value
);
co_return
;
}
Join
<
void
>
parallel
()
{
Future
<
int
>
f
;
printf
(
"[%u] fork(consume())
\n
"
,
Scheduler
::
thread_id
);
co_await
fork
(
consume
(
f
));
printf
(
"[%u] fork(produce())
\n
"
,
Scheduler
::
thread_id
);
co_await
fork
(
produce
(
f
,
20
));
}
Root
root
()
{
co_await
parallel
();
}
int
main
()
{
root
().
call
();
puts
(
"done"
);
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment