Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Token Ring Algorithm does not work for the Haskell backend #20

Open
awsaf opened this issue Oct 31, 2018 · 0 comments
Open

Token Ring Algorithm does not work for the Haskell backend #20

awsaf opened this issue Oct 31, 2018 · 0 comments

Comments

@awsaf
Copy link

awsaf commented Oct 31, 2018

The code below is my attempt at implementing the Token Ring Algorithm. Only two nodes can access the resources after which the program terminates. The await statements were used to force Haskell to execute the statements. It works for the Erlang backend so I am guessing the issue is with the Haskell backend.

`module TokenRingMod;

def Int numNodes() = 10;

interface Node {
Unit setNextNode(Node n);
Unit setTokenAtt();
}

interface Server{
Unit resources(Int id);
}

class ServerImpl implements Server{
Unit resources(Int id){
println("resources accessed by node: " + toString(id));

}
}

class NodeImpl(Int id, Server s) implements Node {

Node next;
Bool hasToken = False;
Unit run(){
if(hasToken == False){
await hasToken == True;
s!resources(id);
hasToken = False;
await next!= null;
await next!setTokenAtt();
}
}

Unit setNextNode(Node n) {
next = n;
}

Unit setTokenAtt(){
this.hasToken = True;
await this.hasToken == False;
}
}

{
List nodes = Nil;
Int num = numNodes();
Server s = new ServerImpl();
Node nextNode;
Node n;
Node first;

first = new NodeImpl(0, s);
nextNode = first;
Int id = num-1;
while (id > 0) {
n = new NodeImpl(id, s);
n!setNextNode(nextNode);
nextNode = n;
nodes = Cons(n,nodes);
id = id -1;
}
assert first != null;
first!setNextNode(n);
await first!setTokenAtt();

}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant