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
fe0843f5
Commit
fe0843f5
authored
Aug 08, 2022
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
examples/: Add programs to test fork policies
parent
edbbe69a
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
117 additions
and
0 deletions
+117
-0
rt/examples/naive_fibonacci_fork_bundle.cpp
rt/examples/naive_fibonacci_fork_bundle.cpp
+27
-0
rt/examples/naive_fibonacci_fork_drop.cpp
rt/examples/naive_fibonacci_fork_drop.cpp
+32
-0
rt/examples/naive_fibonacci_fork_refcnt.cpp
rt/examples/naive_fibonacci_fork_refcnt.cpp
+27
-0
rt/examples/naive_fibonacci_fork_void.cpp
rt/examples/naive_fibonacci_fork_void.cpp
+31
-0
No files found.
rt/examples/naive_fibonacci_fork_bundle.cpp
0 → 100644
View file @
fe0843f5
#include <typon/typon.hpp>
#include <cstdio>
using
namespace
typon
;
using
namespace
typon
::
policy
;
Join
<
int
>
fibo
(
int
n
)
{
if
(
n
<
2
)
{
co_return
n
;
}
Forked
a
=
co_await
fork
<
Bundle
>
(
fibo
(
n
-
1
));
Forked
b
=
co_await
fork
<
Bundle
>
(
fibo
(
n
-
2
));
co_await
Sync
();
co_return
a
.
get
()
+
b
.
get
();
}
Root
root
()
{
int
result
=
co_await
fibo
(
40
);
printf
(
"%d
\n
"
,
result
);
}
int
main
()
{
root
().
call
();
puts
(
"done"
);
return
0
;
}
rt/examples/naive_fibonacci_fork_drop.cpp
0 → 100644
View file @
fe0843f5
#include <typon/typon.hpp>
#include <cstdio>
using
namespace
typon
;
using
namespace
typon
::
policy
;
Join
<
int
>
fibo
(
int
n
,
int
&
result
)
{
if
(
n
<
2
)
{
result
=
n
;
co_return
n
;
}
// Danger !
// The memory for a and b could be freed before the forks complete
int
a
;
co_await
fork
<
Drop
>
(
fibo
(
n
-
1
,
a
));
int
b
;
co_await
fork
<
Drop
>
(
fibo
(
n
-
2
,
b
));
// This sync() ensures that the forks complete before a and b are freed
// As long as there are no exceptions...
co_await
Sync
();
result
=
a
+
b
;
}
Root
root
()
{
int
result
;
co_await
fibo
(
40
,
result
);
printf
(
"%d
\n
"
,
result
);
}
int
main
()
{
root
().
call
();
puts
(
"done"
);
return
0
;
}
rt/examples/naive_fibonacci_fork_refcnt.cpp
0 → 100644
View file @
fe0843f5
#include <typon/typon.hpp>
#include <cstdio>
using
namespace
typon
;
using
namespace
typon
::
policy
;
Join
<
int
>
fibo
(
int
n
)
{
if
(
n
<
2
)
{
co_return
n
;
}
Forked
a
=
co_await
fork
<
Refcnt
>
(
fibo
(
n
-
1
));
Forked
b
=
co_await
fork
<
Refcnt
>
(
fibo
(
n
-
2
));
co_await
Sync
();
co_return
a
.
get
()
+
b
.
get
();
}
Root
root
()
{
int
result
=
co_await
fibo
(
40
);
printf
(
"%d
\n
"
,
result
);
}
int
main
()
{
root
().
call
();
puts
(
"done"
);
return
0
;
}
rt/examples/naive_fibonacci_fork_void.cpp
0 → 100644
View file @
fe0843f5
#include <typon/typon.hpp>
#include <cstdio>
using
namespace
typon
;
Join
<
void
>
fibo
(
int
n
,
int
&
result
)
{
if
(
n
<
2
)
{
result
=
n
;
co_return
;
}
// Danger !
// The memory for a and b could be freed before the forks complete
int
a
;
co_await
fork
(
fibo
(
n
-
1
,
a
));
int
b
;
co_await
fork
(
fibo
(
n
-
2
,
b
));
// This sync() ensures that the forks complete before a and b are freed
// As long as there are no exceptions...
co_await
Sync
();
result
=
a
+
b
;
}
Root
root
()
{
int
result
;
co_await
fibo
(
40
,
result
);
printf
(
"%d
\n
"
,
result
);
}
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