You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 {
{
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();
}`
The text was updated successfully, but these errors were encountered:
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();
}`
The text was updated successfully, but these errors were encountered: