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
6be5c76b
Commit
6be5c76b
authored
Feb 10, 2015
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use `behavior::assign` to initialize philosophers
parent
90b8333f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
10 deletions
+10
-10
examples/message_passing/dining_philosophers.cpp
examples/message_passing/dining_philosophers.cpp
+10
-10
No files found.
examples/message_passing/dining_philosophers.cpp
View file @
6be5c76b
...
@@ -99,24 +99,24 @@ class philosopher : public event_based_actor {
...
@@ -99,24 +99,24 @@ class philosopher : public event_based_actor {
left
(
l
),
left
(
l
),
right
(
r
)
{
right
(
r
)
{
// a philosopher that receives {eat} stops thinking and becomes hungry
// a philosopher that receives {eat} stops thinking and becomes hungry
thinking
=
behavior
{
thinking
.
assign
(
[
=
](
eat_atom
)
{
[
=
](
eat_atom
)
{
become
(
hungry
);
become
(
hungry
);
send
(
left
,
take_atom
::
value
);
send
(
left
,
take_atom
::
value
);
send
(
right
,
take_atom
::
value
);
send
(
right
,
take_atom
::
value
);
}
}
}
;
)
;
// wait for the first answer of a chopstick
// wait for the first answer of a chopstick
hungry
=
behavior
{
hungry
.
assign
(
[
=
](
taken_atom
)
{
[
=
](
taken_atom
)
{
become
(
granted
);
become
(
granted
);
},
},
[
=
](
busy_atom
)
{
[
=
](
busy_atom
)
{
become
(
denied
);
become
(
denied
);
}
}
}
;
)
;
// philosopher was able to obtain the first chopstick
// philosopher was able to obtain the first chopstick
granted
=
behavior
{
granted
.
assign
(
[
=
](
taken_atom
)
{
[
=
](
taken_atom
)
{
aout
(
this
)
<<
name
aout
(
this
)
<<
name
<<
" has picked up chopsticks with IDs "
<<
" has picked up chopsticks with IDs "
...
@@ -131,9 +131,9 @@ class philosopher : public event_based_actor {
...
@@ -131,9 +131,9 @@ class philosopher : public event_based_actor {
send
(
this
,
eat_atom
::
value
);
send
(
this
,
eat_atom
::
value
);
become
(
thinking
);
become
(
thinking
);
}
}
}
;
)
;
// philosopher was *not* able to obtain the first chopstick
// philosopher was *not* able to obtain the first chopstick
denied
=
behavior
{
denied
.
assign
(
[
=
](
taken_atom
)
{
[
=
](
taken_atom
)
{
send
(
last_sender
()
==
left
?
left
:
right
,
put_atom
::
value
);
send
(
last_sender
()
==
left
?
left
:
right
,
put_atom
::
value
);
send
(
this
,
eat_atom
::
value
);
send
(
this
,
eat_atom
::
value
);
...
@@ -143,9 +143,9 @@ class philosopher : public event_based_actor {
...
@@ -143,9 +143,9 @@ class philosopher : public event_based_actor {
send
(
this
,
eat_atom
::
value
);
send
(
this
,
eat_atom
::
value
);
become
(
thinking
);
become
(
thinking
);
}
}
}
;
)
;
// philosopher obtained both chopstick and eats (for five seconds)
// philosopher obtained both chopstick and eats (for five seconds)
eating
=
behavior
{
eating
.
assign
(
[
=
](
think_atom
)
{
[
=
](
think_atom
)
{
send
(
left
,
put_atom
::
value
);
send
(
left
,
put_atom
::
value
);
send
(
right
,
put_atom
::
value
);
send
(
right
,
put_atom
::
value
);
...
@@ -153,7 +153,7 @@ class philosopher : public event_based_actor {
...
@@ -153,7 +153,7 @@ class philosopher : public event_based_actor {
aout
(
this
)
<<
name
<<
" puts down his chopsticks and starts to think
\n
"
;
aout
(
this
)
<<
name
<<
" puts down his chopsticks and starts to think
\n
"
;
become
(
thinking
);
become
(
thinking
);
}
}
}
;
)
;
}
}
protected:
protected:
...
...
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