Skip to content

Instantly share code, notes, and snippets.

@albertnetymk
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save albertnetymk/88f3be200b13a041bc5a to your computer and use it in GitHub Desktop.
Save albertnetymk/88f3be200b13a041bc5a to your computer and use it in GitHub Desktop.
class Client {
server : Server
def init(s:Server) : void {
this.server = s
}
def block() : void {
get this.server.f();
}
def nonblock() : void {
print "nonblock"
}
def dummy() : void {
();
}
}
class Server {
def init() : void {
();
}
def bubbleSort(arr:[int], head:int, tail:int) : void {
let
swapped = true
tmp = 0
in {
while (swapped) {
swapped = false;
while (head < tail - 1) {
if (arr[head] > arr[head+1]) then {
tmp = arr[head];
arr[head] = arr[head+1];
arr[head+1] = tmp;
swapped = true;
};
head = head + 1;
};
}
}
}
def heavy() : void {
print "heavy";
let
length = 100*1000*1000
arr = new [int](length)
in {
repeat i <- length {
arr[i] = i+1
};
this.bubbleSort(arr, 0, length)
}
}
def f() : void {
this.heavy();
}
}
class Main {
def main() : void {
let
s = new Server()
c1 = new Client(s)
c2 = new Client(s)
in {
c1.block();
c2.dummy();
c2.nonblock();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment