aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar zinc <zinc@downsta.ir> 2026-10-15 20:23:23 +0330
committerGravatar zinc <zinc@downsta.ir> 2026-10-15 20:23:23 +0330
commit35538c83c1f9f9c95a850a2b4a78002c5b467653 (patch)
tree91acab7da09c9225a2d838791d70e5c2e7db54b9
parentxref baseline: lkval (local const values) and xcval folded in bin (diff)
examples/actors_demo: print the fan-out replies in worker order, not arrival order (the x86-64 jit vs interpreter check flaked on it under load)
-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);