Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
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
Operations
Operations
Metrics
Environments
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
cpp-libs
Actor Framework
Commits
f503ca4e
Commit
f503ca4e
authored
Feb 01, 2013
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added `spawn_link` and `spawn_monitor`
parent
7fb9fdb9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
95 additions
and
5 deletions
+95
-5
cppa/cppa.hpp
cppa/cppa.hpp
+92
-0
unit_testing/test__spawn.cpp
unit_testing/test__spawn.cpp
+3
-5
No files found.
cppa/cppa.hpp
View file @
f503ca4e
...
@@ -785,6 +785,98 @@ actor_ptr spawn_hidden(Args&&... args) {
...
@@ -785,6 +785,98 @@ actor_ptr spawn_hidden(Args&&... args) {
#endif
#endif
/**
* @brief Spawns a new context-switching or thread-mapped {@link actor}
* that executes <tt>fun(args...)</tt> and creates a link between the
* calling actor and the new actor.
* @param fun A function implementing the actor's behavior.
* @param args Optional function parameters for @p fun.
* @tparam Hint A hint to the scheduler for the best scheduling strategy.
* @returns An {@link actor_ptr} to the spawned {@link actor}.
*/
template
<
scheduling_hint
Hint
,
typename
Fun
,
typename
...
Args
>
actor_ptr
spawn_link
(
Fun
&&
fun
,
Args
&&
...
args
)
{
auto
res
=
spawn
<
Hint
>
(
std
::
forward
<
Fun
>
(
fun
),
std
::
forward
<
Args
>
(
args
)...);
self
->
link_to
(
res
);
return
res
;
}
/**
* @brief Spawns a new context-switching {@link actor}
* that executes <tt>fun(args...)</tt> and creates a link between the
* calling actor and the new actor.
* @param fun A function implementing the actor's behavior.
* @param args Optional function parameters for @p fun.
* @returns An {@link actor_ptr} to the spawned {@link actor}.
* @note This function is equal to <tt>spawn<scheduled>(fun, args...)</tt>.
*/
template
<
typename
Fun
,
typename
...
Args
>
actor_ptr
spawn_link
(
Fun
&&
fun
,
Args
&&
...
args
)
{
auto
res
=
spawn
(
std
::
forward
<
Fun
>
(
fun
),
std
::
forward
<
Args
>
(
args
)...);
self
->
link_to
(
res
);
return
res
;
}
/**
* @brief Spawns an actor of type @p ActorImpl and creates a link between the
* calling actor and the new actor.
* @param args Optional constructor arguments.
* @tparam ActorImpl Subtype of {@link event_based_actor} or {@link sb_actor}.
* @returns An {@link actor_ptr} to the spawned {@link actor}.
*/
template
<
class
ActorImpl
,
typename
...
Args
>
actor_ptr
spawn_link
(
Args
&&
...
args
)
{
auto
res
=
spawn
<
ActorImpl
>
(
std
::
forward
<
Args
>
(
args
)...);
self
->
link_to
(
res
);
return
res
;
}
/**
* @brief Spawns a new context-switching or thread-mapped {@link actor}
* that executes <tt>fun(args...)</tt> and adds a monitor to the
* new actor.
* @param fun A function implementing the actor's behavior.
* @param args Optional function parameters for @p fun.
* @tparam Hint A hint to the scheduler for the best scheduling strategy.
* @returns An {@link actor_ptr} to the spawned {@link actor}.
*/
template
<
scheduling_hint
Hint
,
typename
Fun
,
typename
...
Args
>
actor_ptr
spawn_monitor
(
Fun
&&
fun
,
Args
&&
...
args
)
{
auto
res
=
spawn
<
Hint
>
(
std
::
forward
<
Fun
>
(
fun
),
std
::
forward
<
Args
>
(
args
)...);
self
->
monitor
(
res
);
return
res
;
}
/**
* @brief Spawns a new context-switching {@link actor}
* that executes <tt>fun(args...)</tt> and adds a monitor to the
* new actor.
* @param fun A function implementing the actor's behavior.
* @param args Optional function parameters for @p fun.
* @returns An {@link actor_ptr} to the spawned {@link actor}.
* @note This function is equal to <tt>spawn<scheduled>(fun, args...)</tt>.
*/
template
<
typename
Fun
,
typename
...
Args
>
actor_ptr
spawn_monitor
(
Fun
&&
fun
,
Args
&&
...
args
)
{
auto
res
=
spawn
(
std
::
forward
<
Fun
>
(
fun
),
std
::
forward
<
Args
>
(
args
)...);
self
->
monitor
(
res
);
return
res
;
}
/**
* @brief Spawns an actor of type @p ActorImpl and adds a monitor to the
* new actor.
* @param args Optional constructor arguments.
* @tparam ActorImpl Subtype of {@link event_based_actor} or {@link sb_actor}.
* @returns An {@link actor_ptr} to the spawned {@link actor}.
*/
template
<
class
ActorImpl
,
typename
...
Args
>
actor_ptr
spawn_monitor
(
Args
&&
...
args
)
{
auto
res
=
spawn
<
ActorImpl
>
(
std
::
forward
<
Args
>
(
args
)...);
self
->
monitor
(
res
);
return
res
;
}
/** @} */
/** @} */
/**
/**
...
...
unit_testing/test__spawn.cpp
View file @
f503ca4e
...
@@ -685,7 +685,7 @@ int main() {
...
@@ -685,7 +685,7 @@ int main() {
// and kill them all through killing the link
// and kill them all through killing the link
auto
twenty_thousand
=
spawn
([]()
{
auto
twenty_thousand
=
spawn
([]()
{
for
(
int
i
=
0
;
i
<
20000
;
++
i
)
{
for
(
int
i
=
0
;
i
<
20000
;
++
i
)
{
s
elf
->
link_to
(
spawn
<
event_testee
>
()
);
s
pawn_link
<
event_testee
>
(
);
}
}
receive_loop
(
receive_loop
(
others
()
>>
[]()
{
others
()
>>
[]()
{
...
@@ -696,10 +696,8 @@ int main() {
...
@@ -696,10 +696,8 @@ int main() {
send
(
twenty_thousand
,
atom
(
"EXIT"
),
exit_reason
::
user_defined
);
send
(
twenty_thousand
,
atom
(
"EXIT"
),
exit_reason
::
user_defined
);
await_all_others_done
();
await_all_others_done
();
self
->
trap_exit
(
true
);
self
->
trap_exit
(
true
);
auto
ping_actor
=
spawn
(
ping
,
10
);
auto
ping_actor
=
spawn_monitor
(
ping
,
10
);
auto
pong_actor
=
spawn
(
pong
,
ping_actor
);
auto
pong_actor
=
spawn_monitor
(
pong
,
ping_actor
);
self
->
monitor
(
pong_actor
);
self
->
monitor
(
ping_actor
);
self
->
link_to
(
pong_actor
);
self
->
link_to
(
pong_actor
);
int
i
=
0
;
int
i
=
0
;
int
flags
=
0
;
int
flags
=
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