Mercurial > hg > Members > nobuyasu > Alice > DPPAlice
changeset 15:7e91e919a7de
modified
author | one |
---|---|
date | Sun, 09 Dec 2012 22:09:46 +0900 |
parents | 33727db069c2 |
children | f5c2fad58b7e |
files | src/alice/test/dpp/codesegment/EatCodeSegment.java src/alice/test/dpp/codesegment/ScheduleCodeSegment.java src/alice/test/dpp/codesegment/TakeForkCodeSegment.java src/alice/test/dpp/codesegment/ThinkCodeSegment.java src/alice/test/dpp/model/Fork.java src/alice/test/dpp/model/Philosophy.java |
diffstat | 6 files changed, 17 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/alice/test/dpp/codesegment/EatCodeSegment.java Wed Nov 28 17:41:42 2012 +0900 +++ b/src/alice/test/dpp/codesegment/EatCodeSegment.java Sun Dec 09 22:09:46 2012 +0900 @@ -21,5 +21,4 @@ new ScheduleCodeSegment(phil.getName()); ods.update("local", phil.getName(), phil); } - }
--- a/src/alice/test/dpp/codesegment/ScheduleCodeSegment.java Wed Nov 28 17:41:42 2012 +0900 +++ b/src/alice/test/dpp/codesegment/ScheduleCodeSegment.java Sun Dec 09 22:09:46 2012 +0900 @@ -20,9 +20,17 @@ case THINK: new ThinkCodeSegment(phil.getName()); break; + case TAKERIGHTFORK: + new TakeOneForkCodeSegment(phil.getName(), phil.getRightFork()); + break; + case TAKELEFTFORK: + new TakeOneForkCodeSegment(phil.getName(), phil.getLeftFork()); + break; +/* case TAKEFORK: new TakeForkCodeSegment(phil.getName(), phil.getRightFork(), phil.getLeftFork() ); break; +*/ case EAT: new EatCodeSegment(phil.getName()); break;
--- a/src/alice/test/dpp/codesegment/TakeForkCodeSegment.java Wed Nov 28 17:41:42 2012 +0900 +++ b/src/alice/test/dpp/codesegment/TakeForkCodeSegment.java Sun Dec 09 22:09:46 2012 +0900 @@ -14,6 +14,7 @@ public TakeForkCodeSegment(String pName, String rFork, String lFork) { arg1.setKey(pName); + // dead lock arg2.setKey(rFork); arg3.setKey(lFork); } @@ -24,12 +25,14 @@ Fork rightFork = arg2.asClass(Fork.class); Fork leftFork = arg3.asClass(Fork.class); System.out.println(phil.getName() + " is trying to take the fork."); + if (leftFork.getFork(phil.getName()) && rightFork.getFork(phil.getName()) ) { phil.setState(Philosophy.State.EAT); } else { leftFork.onTheTable(phil.getName()); rightFork.onTheTable(phil.getName()); } + new ScheduleCodeSegment(phil.getName()); ods.update("local", phil.getName(), phil); ods.update("local", leftFork.getForkName(), leftFork);
--- a/src/alice/test/dpp/codesegment/ThinkCodeSegment.java Wed Nov 28 17:41:42 2012 +0900 +++ b/src/alice/test/dpp/codesegment/ThinkCodeSegment.java Sun Dec 09 22:09:46 2012 +0900 @@ -17,7 +17,8 @@ public void run() { Philosophy phil = arg1.asClass(Philosophy.class); System.out.println(phil.getName() + " is thinking"); - phil.setState(Philosophy.State.TAKEFORK); +// phil.setState(Philosophy.State.TAKEFORK); // dead lock + phil.setState(Philosophy.State.TAKERIGHTFORK); new ScheduleCodeSegment(phil.getName()); ods.update("local", phil.getName(), phil); }
--- a/src/alice/test/dpp/model/Fork.java Wed Nov 28 17:41:42 2012 +0900 +++ b/src/alice/test/dpp/model/Fork.java Sun Dec 09 22:09:46 2012 +0900 @@ -36,7 +36,7 @@ } public boolean getFork(String pName) { - if (state == State.ON_THE_TABLE){ + if (state == State.ON_THE_TABLE) { state = State.IN_THE_HAND; owner = pName; return true;
--- a/src/alice/test/dpp/model/Philosophy.java Wed Nov 28 17:41:42 2012 +0900 +++ b/src/alice/test/dpp/model/Philosophy.java Sun Dec 09 22:09:46 2012 +0900 @@ -13,6 +13,8 @@ @MessagePackOrdinalEnum public static enum State { THINK, + TAKERIGHTFORK, + TAKELEFTFORK, TAKEFORK, EAT, PUTFORK; @@ -21,6 +23,7 @@ private String name, leftFork, rightFork; private State state; + public Philosophy() {} public Philosophy(String n,String lFork, String rFork) {