From 25aa655e5b9464e291d542081ed1cf0f8fd666af Mon Sep 17 00:00:00 2001 From: zinc Date: Thu, 15 Oct 2026 14:33:28 +0330 Subject: hold: fixtures (accept, reject, race, rank order) and tests/drivers/hold_test.py --- tests/hold/accept/race.zc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/hold/accept/race.zc (limited to 'tests/hold/accept/race.zc') 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*[?] xs = rt.new(actor.Actor*[?]); + while (i < 8) { actor.Actor* a = rt.new(actor.Actor); 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; +} -- cgit v1.2.3