From fc89e5ea115d6da2217b52a87ba8eb73c207e916 Mon Sep 17 00:00:00 2001 From: zinc Date: Thu, 15 Oct 2026 02:51:54 +0330 Subject: 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 --- tests/actor/accept/drop_closes.zc | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/actor/accept/drop_closes.zc (limited to 'tests/actor') 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; +} -- cgit v1.2.3