aboutsummaryrefslogtreecommitdiff
path: root/examples/actors_demo.zc
diff options
context:
space:
mode:
authorGravatar zinc <zinc@downsta.ir> 2026-10-15 21:44:40 +0330
committerGravatar zinc <zinc@downsta.ir> 2026-10-15 21:44:40 +0330
commitf3dcfd9805e1bd23b002f648d4391ec397122d9c (patch)
tree91acab7da09c9225a2d838791d70e5c2e7db54b9 /examples/actors_demo.zc
parentmerge work/small-oob: bytes test out-of-bounds read (diff)
parentexamples/actors_demo: print the fan-out replies in worker order, not arrival ... (diff)
merge work/known-bugs: constant-expression precedence, local const in constant expressions, duplicate case labels, unterminated strings, droppable cycles in one collection, js vm exit, docs, actors_demo orderHEADmain
Diffstat (limited to 'examples/actors_demo.zc')
-rw-r--r--examples/actors_demo.zc15
1 files changed, 11 insertions, 4 deletions
diff --git a/examples/actors_demo.zc b/examples/actors_demo.zc
index 656e131..9e4a8ed 100644
--- a/examples/actors_demo.zc
+++ b/examples/actors_demo.zc
@@ -62,24 +62,31 @@ fn main() {
while (!done) for (int i = 0; i < N; i++) ring[i].poll();
for (int i = 0; i < N; i++) ring[i].close();
- // fan-out: W workers in parallel, results arrive as they finish
+ // fan-out: W workers in parallel. replies arrive in whatever order the workers
+ // finish, so each is stored by worker and printed in worker order afterwards
color(2); rt.put_s("\nfan-out: "); rt.put_n(W); rt.put_s(" crunchers, collatz over 80000 starts\n"); plain();
Crunch*[4] pool;
+ int[4] chain;
+ int* cp = &chain[0];
let answers = 0, best = 0;
for (int i = 0; i < W; i++) {
pool[i] = rt.new(Crunch); pool[i].spawn();
let me = i;
pool[i].recv(fn(int k) {
answers++; if (k > best) best = k;
- color(4); rt.put_s(" worker "); rt.put_n(me); plain();
- rt.put_s(" ["); rt.put_n(me * 20000 + 1); rt.put_s(".."); rt.put_n(me * 20000 + 20000); rt.put_s("] longest chain ");
- color(6); rt.put_n(k); plain(); rt.put_c(' '); bar(k / 8, 4 + me % 3); rt.put_c(10);
+ cp[me] = k;
return 0;
});
pool[i].send(i * 20000 + 1);
}
for (int i = 0; i < W; i++) pool[i].await();
for (int i = 0; i < W; i++) pool[i].close();
+ for (int i = 0; i < W; i++) {
+ int k = chain[i];
+ color(4); rt.put_s(" worker "); rt.put_n(i); plain();
+ rt.put_s(" ["); rt.put_n(i * 20000 + 1); rt.put_s(".."); rt.put_n(i * 20000 + 20000); rt.put_s("] longest chain ");
+ color(6); rt.put_n(k); plain(); rt.put_c(' '); bar(k / 8, 4 + i % 3); rt.put_c(10);
+ }
color(5); rt.put_s("\n== summary ==\n"); plain();
rt.put_s(" ring hops: "); color(3); rt.put_n(hops); plain(); rt.put_c(10);