aboutsummaryrefslogtreecommitdiff
path: root/tests/actor/accept
diff options
context:
space:
mode:
authorGravatar zinc <zinc@downsta.ir> 2026-10-15 02:51:54 +0330
committerGravatar zinc <zinc@downsta.ir> 2026-10-15 02:51:54 +0330
commitfc89e5ea115d6da2217b52a87ba8eb73c207e916 (patch)
treec5b8e69edd139b8863bb32bcbdecff3bab03ebc5 /tests/actor/accept
parentstd: File, the first user of drops: std.Host.open(path, mode) returns an owne... (diff)
actor: a declared actor without its own drop gets one that awaits owed replies and closes the endpoint; the handler reaches the struct through endpoint.state so the struct isn't shared; spawn hint skips mailbox structs
Diffstat (limited to 'tests/actor/accept')
-rw-r--r--tests/actor/accept/drop_closes.zc25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/actor/accept/drop_closes.zc b/tests/actor/accept/drop_closes.zc
new file mode 100644
index 0000000..08fd02c
--- /dev/null
+++ b/tests/actor/accept/drop_closes.zc
@@ -0,0 +1,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;
+}