Skip to content

Commit

Permalink
Adding
Browse files Browse the repository at this point in the history
  • Loading branch information
oleander committed Feb 17, 2011
1 parent 4689ea3 commit 1730064
Showing 1 changed file with 25 additions and 81 deletions.
106 changes: 25 additions & 81 deletions SimpleClock.jr
@@ -1,81 +1,25 @@
import java.util.*;
import edu.ucdavis.jr.*;

public class SimpleClock {

public op boolean tick();
public cap void() alarmCap;

private int delay;

public SimpleClock(int delay) {
this.delay = delay;
this.alarmCap = new op void();
send timer(alarmCap, delay*3);

}


private process ticker {
long next = System.nanoTime();
long w;
boolean shouldContinue;
do {
next += (delay*1000000);
w = Math.max(0,(next-System.nanoTime())/1000000);
edu.ucdavis.jr.JR.nap(w);
shouldContinue = tick();
System.out.println("Tickresult: " + shouldContinue);
} while (shouldContinue);
System.out.println("tickerprocessen avslutas ...");

}

public op void timer(cap void() alarm, int ms) {
edu.ucdavis.jr.JR.nap(ms);
alarm();
}

//Nedan är kod för som är ekvivalent med ovanstående timer
/*
public op void timer(cap void() alarm, int ms);

public process abc
{
cap void() alarm;
int ms;
while(true)
{
receive timer(alarm, ms);
edu.ucdavis.jr.JR.nap(ms);
alarm();

}
}
*/

public process listener
{

while(true)
{
inni boolean tick()
{
System.out.println("Tick");
return true;
}
[] void alarmCap()
{
break;
}
}
System.out.println("Nu har alarmet gått");

}


public static void main(String[] args) {
new SimpleClock(1000);
System.out.println("Done.");
}
}
import java.util.*;
import edu.ucdavis.jr.*;

public class SimpleClock {

public op boolean tick();
public cap void() alarmCap;

private int delay;

public SimpleClock(int delay) {
this.delay = delay;
this.alarmCap = new op void();
send timer(alarmCap, delay*3);

}


private process ticker {
long next = System.nanoTime();
long w;
boolean shouldContinue;
do {
next += (delay*1000000);
w = Math.max(0,(next-System.nanoTime())/1000000);

0 comments on commit 1730064

Please sign in to comment.