Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
typon-concurrency
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
typon
typon-concurrency
Commits
6004d476
Commit
6004d476
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
8e6211d3
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 @
6004d476
#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 @
6004d476
#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 @
6004d476
#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 @
6004d476
#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