aboutsummaryrefslogtreecommitdiff
path: root/tests/hold/accept/race.zc
diff options
context:
space:
mode:
authorGravatar zinc <zinc@downsta.ir> 2026-10-15 14:33:28 +0330
committerGravatar zinc <zinc@downsta.ir> 2026-10-15 14:33:28 +0330
commit25aa655e5b9464e291d542081ed1cf0f8fd666af (patch)
treefb2fa4b3e77914ab00829b39142a2f8cfb3a9d8b /tests/hold/accept/race.zc
parenthold blocks: top-level hold { shared let ...; fn ... } monitors; shared value... (diff)
hold: fixtures (accept, reject, race, rank order) and tests/drivers/hold_test.py
Diffstat (limited to 'tests/hold/accept/race.zc')
-rw-r--r--tests/hold/accept/race.zc21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/hold/accept/race.zc b/tests/hold/accept/race.zc
new file mode 100644
index 0000000..f7fdb61
--- /dev/null
+++ b/tests/hold/accept/race.zc
@@ -0,0 +1,21 @@
+// expect: 90000
+// many actors increment one shared counter through a read, then a write; the hold block's lock makes every increment count
+namespace;
+include rt, actor;
+typecheck on;
+hold {
+ shared let count = 0;
+ fn inc() { let v = count; count = v + 1; return v; }
+ fn total() { return count; }
+}
+int work(int n) { let i = 0; while (i < n) { inc(); i++; } return n; }
+fn main() {
+ let i = 0; actor.Actor<int,int>*[?] xs = rt.new(actor.Actor<int,int>*[?]);
+ while (i < 8) { actor.Actor<int,int>* a = rt.new(actor.Actor<int,int>); a.spawn(work); push(xs, a); i++; }
+ i = 0; while (i < 8) { xs[i].send(10000); i++; }
+ work(10000);
+ i = 0; while (i < 8) { xs[i].recv(fn(int n) { return 0; }); xs[i].await(); i++; }
+ rt.put_n(total()); rt.put_c(10);
+ i = 0; while (i < 8) { xs[i].close(); i++; }
+ return 0;
+}