Skip to content

Commit

Permalink
Updated dining-philos examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Baha committed Dec 6, 2017
1 parent a1762ce commit ec1416a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 29 deletions.
10 changes: 3 additions & 7 deletions examples/dining.erl
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
-module(dining).
-export([main/0, waiter/1, fork/1, philo/2]).
-export([main/0, waiter/0, fork/1, philo/2]).

main() ->
spawn(?MODULE, waiter, [self()]),
receive
table_prepared -> ok
end.
spawn(?MODULE, waiter, []).

spawn_forks(0, Dict) ->
Dict;
Expand All @@ -19,10 +16,9 @@ spawn_philos(N, Dict, Pid) ->
Pair = {spawn(?MODULE, philo, [Pid, N]), N},
spawn_philos(N-1, [Pair] ++ Dict, Pid).

waiter(DiningPid) ->
waiter() ->
ForkDict = spawn_forks(5, []),
PhiloDict = spawn_philos(5, [], self()),
DiningPid ! table_prepared,
waiter_1(ForkDict, PhiloDict).

waiter_1(ForkDict, PhiloDict) ->
Expand Down
10 changes: 3 additions & 7 deletions examples/dining_bug.erl
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
-module(dining_bug).
-export([main/0, waiter/1, fork/1, philo/2]).
-export([main/0, waiter/0, fork/1, philo/2]).

main() ->
spawn(?MODULE, waiter, [self()]),
receive
table_prepared -> ok
end.
spawn(?MODULE, waiter, []).

spawn_forks(0, Dict) ->
Dict;
Expand All @@ -19,10 +16,9 @@ spawn_philos(N, Dict, Pid) ->
Pair = {spawn(?MODULE, philo, [Pid, N]), N},
spawn_philos(N-1, [Pair] ++ Dict, Pid).

waiter(DiningPid) ->
waiter() ->
ForkDict = spawn_forks(5, []),
PhiloDict = spawn_philos(5, [], self()),
DiningPid ! table_prepared,
waiter_1(ForkDict, PhiloDict).

waiter_1(ForkDict, PhiloDict) ->
Expand Down
10 changes: 3 additions & 7 deletions examples/dining_simple.erl
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
-module(dining_simple).
-export([main/0, waiter/1, fork/1, philo/2]).
-export([main/0, waiter/0, fork/1, philo/2]).

main() ->
spawn(?MODULE, waiter, [self()]),
receive
table_prepared -> ok
end.
spawn(?MODULE, waiter, []).

spawn_forks(0, Dict) ->
Dict;
Expand All @@ -19,10 +16,9 @@ spawn_philos(N, Dict, Pid) ->
Pair = {spawn(?MODULE, philo, [Pid, N]), N},
spawn_philos(N-1, [Pair] ++ Dict, Pid).

waiter(DiningPid) ->
waiter() ->
ForkDict = spawn_forks(5, []),
PhiloDict = spawn_philos(5, [], self()),
DiningPid ! table_prepared,
waiter_1(ForkDict, PhiloDict).

waiter_1(ForkDict, PhiloDict) ->
Expand Down
12 changes: 4 additions & 8 deletions examples/dining_simple_bug.erl
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
-module(dining_simple).
-export([main/0, waiter/1, fork/1, philo/2]).
-module(dining_simple_bug).
-export([main/0, waiter/0, fork/1, philo/2]).

main() ->
spawn(?MODULE, waiter, [self()]),
receive
table_prepared -> ok
end.
spawn(?MODULE, waiter, []).

spawn_forks(0, Dict) ->
Dict;
Expand All @@ -19,10 +16,9 @@ spawn_philos(N, Dict, Pid) ->
Pair = {spawn(?MODULE, philo, [Pid, N]), N},
spawn_philos(N-1, [Pair] ++ Dict, Pid).

waiter(DiningPid) ->
waiter() ->
ForkDict = spawn_forks(5, []),
PhiloDict = spawn_philos(5, [], self()),
DiningPid ! table_prepared,
waiter_1(ForkDict, PhiloDict).

waiter_1(ForkDict, PhiloDict) ->
Expand Down

0 comments on commit ec1416a

Please sign in to comment.