Mercurial > hg > Members > nobuyasu > Alice > DPPAlice
view src/alice/test/dpp/codesegment/TakeForkCodeSegment.java @ 20:6018e62cb198 dead lock dpp
modified
author | one |
---|---|
date | Sun, 09 Dec 2012 23:09:04 +0900 |
parents | 7e91e919a7de |
children | fd370b35fac1 |
line wrap: on
line source
package alice.test.dpp.codesegment; import alice.codesegment.CodeSegment; import alice.datasegment.CommandType; import alice.datasegment.Receiver; import alice.test.dpp.datasegment.Fork; import alice.test.dpp.datasegment.Philosophy; public class TakeForkCodeSegment extends CodeSegment { Receiver arg1 = ids.create(CommandType.TAKE); Receiver arg2 = ids.create(CommandType.TAKE); Receiver arg3 = ids.create(CommandType.TAKE); public TakeForkCodeSegment(String pName, String rFork, String lFork) { arg1.setKey(pName); // dead lock arg2.setKey(rFork); arg3.setKey(lFork); } @Override public void run() { Philosophy phil = arg1.asClass(Philosophy.class); 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); ods.update("local", rightFork.getForkName(), rightFork); } }