forked from oleander/The-Pub-Simulation
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
25 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |