java语言中的fork语句
我必须使用以下规则在我的玩具语言中实现fork语句:java语言中的fork语句,java,multithreading,Java,Multithreading,我必须使用以下规则在我的玩具语言中实现fork语句: ExeStack1={fork(Stmt1) | Stmt2|Stmt3|....} SymTable1, Heap1, Out1, id1 ==> ExeStack2={Stmt2 | Stmt3|.....} SymTable2=SymTable1 Heap2 = Heap1 Out2 = Out1 id2=id1 and a new PrgSate is created with the following data struct
ExeStack1={fork(Stmt1) | Stmt2|Stmt3|....}
SymTable1,
Heap1,
Out1,
id1
==>
ExeStack2={Stmt2 | Stmt3|.....}
SymTable2=SymTable1
Heap2 = Heap1
Out2 = Out1
id2=id1
and a new PrgSate is created with the following data structures:
ExeStack3=Stmt1
SymTable3=clone(SymTable1)
Heap3=Heap1,
Out3=Out1
id3= id1*10 in order to be unique
注意:新的PrgState由execute方法返回。如上所述,当fork语句位于ExeStack之上时,将生成一个新的PrgState(thread),其中包含fork的参数ExeStack、父PrgState(父线程)的克隆SymTable、对父PrgState(父线程)堆的引用Heap和对父PrgState(父线程)的引用Out出来请注意,Heap和Out由所有prgstate共享。新线程的符号表是克隆(或新副本),并且
未与父线程共享。
我实现了如下内容:
public class ForkStmt implements IStmt,Serializable{
IStmt stmt;
public ForkStmt(IStmt st){
stmt= st;
}
public IStmt getStmt(){
return stmt;
}
public String toString(){
return "fork(" + stmt + ")";
}
public PrgState execute(PrgState prg){
IStack<IStmt> a =prg.getStk();
a = (IStack<IStmt>)stmt;
Id<Object,Integer> dictRef = prg.getDict();
IHeap<Integer,Integer> h = prg.getHeap();
IList<Object> l = prg.getList();
PrgState forkPrg = new PrgState(a,dictRef,l,h);
return forkPrg;
}
公共类forksmt实现IStmt,可序列化{
IStmt stmt;
公共分岔路口(IStmt街){
stmt=st;
}
公共IStmt getStmt(){
返回stmt;
}
公共字符串toString(){
返回“fork(“+stmt+”);
}
公共PrgState执行(PrgState prg){
IStack a=prg.getStk();
a=(IStack)stmt;
Id dictRef=prg.getDict();
IHeap h=prg.getHeap();
IList l=prg.getList();
PrgState forkPrg=新的PrgState(a,dictRef,l,h);
返回叉PRG;
}
}
它是好的吗?谢谢。您是否运行了一些测试来检查它是否有效?是否有效?你有什么问题吗?嗯,我的项目正在运行,但它给了我这个项目的另一部分的一些例外,以及该部分如何与这个forksmt连接。我确信这个实现出了一些问题。请发布你得到的所有错误。如果不看到这个,就无法诊断问题!请把它添加到你的问题中。