1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
// destructors: an actor's drop waits for the replies its receiver is owed, then closes the endpoint, so the worker is gone when the owner's block ends; a struct that declares its own drop keeps it
namespace;
include rt, actor;
actor Echo { int total; int handle(int x) { return x; } }
int closed;
actor Mine { int total; int handle(int x) { return x; } void drop() { closed++; } }
fn main() {
int before = rt.syscall(55, 0, 0, 0);
{
Echo* e = rt.new(Echo);
e.spawn();
rt.put_n(rt.syscall(55, 0, 0, 0) - before); rt.put_c(32);
}
rt.put_n(rt.syscall(55, 0, 0, 0) - before); rt.put_c(32);
let total = 0;
{
Echo* f = rt.new(Echo);
f.spawn(); f.recv(fn(int n) { total += n; return 0; }); f.send(5); f.send(6);
}
rt.put_n(total); rt.put_c(32);
rt.put_n(rt.syscall(55, 0, 0, 0) - before); rt.put_c(32);
{ Mine* m = rt.new(Mine); }
rt.put_n(closed); rt.put_c(10);
return 0;
}
|