summaryrefslogtreecommitdiff
path: root/chapter33/src/test/smp/separate
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2026-11-17 08:19:48 -0800
committerCliff Click <cliffc@acm.org>2026-11-17 08:19:48 -0800
commitb62b00d6c5953c4a2f3b60c09e50e776f901bac6 (patch)
tree3f3ef04fe8803c8de7dd45c4cf5e67f5fd599d11 /chapter33/src/test/smp/separate
parentebdb2c71237506d67cfa8f3bb459b41902840481 (diff)
downloadSimple-b62b00d6c5953c4a2f3b60c09e50e776f901bac6.tar.gz
Simple-b62b00d6c5953c4a2f3b60c09e50e776f901bac6.zip
First cut ch33
Diffstat (limited to 'chapter33/src/test/smp/separate')
-rw-r--r--chapter33/src/test/smp/separate/client/Main.smp6
-rw-r--r--chapter33/src/test/smp/separate/library/Counters.smp12
2 files changed, 18 insertions, 0 deletions
diff --git a/chapter33/src/test/smp/separate/client/Main.smp b/chapter33/src/test/smp/separate/client/Main.smp
new file mode 100644
index 00000000..e70079db
--- /dev/null
+++ b/chapter33/src/test/smp/separate/client/Main.smp
@@ -0,0 +1,6 @@
+val run={int n ->
+ if(!n) return 0;
+ val c=new Counters.Counter(n);
+ return c.get()+100*Counters.next_noInline();
+};
+int n=arg; return run(n);
diff --git a/chapter33/src/test/smp/separate/library/Counters.smp b/chapter33/src/test/smp/separate/library/Counters.smp
new file mode 100644
index 00000000..a3e36562
--- /dev/null
+++ b/chapter33/src/test/smp/separate/library/Counters.smp
@@ -0,0 +1,12 @@
+// A library can keep shared state and publish instance constructors.
+int calls=0;
+val next_noInline={ -> calls++; return calls; };
+
+struct Counter {
+ val value=1;
+ new Counter={int n ->
+ value=0;
+ for(int i=0; i<n; i++) value=value*2+1;
+ };
+ val get={ -> value; };
+};