From ec1416acf2805de670ede9ab79869091b7ac2b93 Mon Sep 17 00:00:00 2001 From: Baha Date: Wed, 6 Dec 2017 12:23:56 +0100 Subject: [PATCH] Updated dining-philos examples --- examples/dining.erl | 10 +++------- examples/dining_bug.erl | 10 +++------- examples/dining_simple.erl | 10 +++------- examples/dining_simple_bug.erl | 12 ++++-------- 4 files changed, 13 insertions(+), 29 deletions(-) diff --git a/examples/dining.erl b/examples/dining.erl index 5e8be37..a0bd114 100644 --- a/examples/dining.erl +++ b/examples/dining.erl @@ -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; @@ -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) -> diff --git a/examples/dining_bug.erl b/examples/dining_bug.erl index 66a3a73..47be51e 100644 --- a/examples/dining_bug.erl +++ b/examples/dining_bug.erl @@ -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; @@ -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) -> diff --git a/examples/dining_simple.erl b/examples/dining_simple.erl index 0495255..58bab72 100644 --- a/examples/dining_simple.erl +++ b/examples/dining_simple.erl @@ -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; @@ -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) -> diff --git a/examples/dining_simple_bug.erl b/examples/dining_simple_bug.erl index dc3d4d3..f33c407 100644 --- a/examples/dining_simple_bug.erl +++ b/examples/dining_simple_bug.erl @@ -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; @@ -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) ->