summaryrefslogtreecommitdiff
path: root/demos/intro.apl
diff options
context:
space:
mode:
authorglenda <glenda@cirno>2022-09-14 08:26:29 +0000
committerglenda <glenda@cirno>2022-09-14 08:26:29 +0000
commit544f90f798a7ebd76b71f094d4cd77f6166e606b (patch)
treee8ce5356dc52300bbe9aaa8fc460c6e0f179d37e /demos/intro.apl
parent2c2af66200badebe076570038daf4cacf47a1281 (diff)
More demos, and lock thread spawning
Diffstat (limited to 'demos/intro.apl')
-rw-r--r--demos/intro.apl33
1 files changed, 33 insertions, 0 deletions
diff --git a/demos/intro.apl b/demos/intro.apl
new file mode 100644
index 0000000..a98bb1e
--- /dev/null
+++ b/demos/intro.apl
@@ -0,0 +1,33 @@
+⍝ The send primitive is a dyadic function
+⍝ message ⍈ to
+
+message←'Hello there'
+
+⍝ We can send it to ourselves
+us←⎕self
+us
+message ⍈ us
+
+⍝ Let's examine the state of the system
+us ⎕threads 0 ⍝ Thread ID
+us ⎕threads 1 ⍝ Thread name
+us ⎕threads 2 ⍝ Number of messages in mailbox
+us ⎕threads 3 ⍝ Approximate C stack usage (in bytes)
+
+⍝ All at once, for all currently running threads
+⎕threads 0 1 2 3
+
+⍝ We have one message in our mailbox, let's receive it
+⍝ The recieve primitive is a monadic operator
+⍝ filter ⍇ timeout
+{1 ⍵} ⍇ 0
+
+⍝ Again?
+{1 ⍵} ⍇ 0
+⍝ The time we asked it to wait was 0, so it failed immediately.
+{1 ⍵} ⍇ 5
+
+⍝ What if we don't want it to timeout?
+{1 ⍵} ⍇ ⍬ ⍝ Noone will send it anything, so it hangs
+
+