diff options
author | glenda <glenda@cirno> | 2022-09-13 13:54:07 +0000 |
---|---|---|
committer | glenda <glenda@cirno> | 2022-09-13 13:54:07 +0000 |
commit | ed5a7271655be2d846d8d1ef37b7f51dd24c8ad9 (patch) | |
tree | 2a7032ff0f754c435081a10e918eb645104e314d | |
parent | 9d2a64a26740982587baab2f5938210bdba9accc (diff) |
Add demo showing message passing
-rw-r--r-- | demos/doubleup.apl | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/demos/doubleup.apl b/demos/doubleup.apl new file mode 100644 index 0000000..44d3cd9 --- /dev/null +++ b/demos/doubleup.apl @@ -0,0 +1,38 @@ +⍝ Define the "double up" function +f←{ + (who message)←{1 ⍵} RECV ⍬ ⍝ Recieve a message with no timeout + (2×message) SEND who ⍝ Reply with 2×message + ∇⍵ ⍝ Recurse + } + +⍝ Spawn it as a seperate thread +id←f&'double up'⊢⍬ + +⍝ Check it's status (id, name, mails in mailbox) +id ⎕tasks 0 1 4 + +⍝ Check our own status +⎕self ⎕tasks 0 1 4 + +⍝ Send a few messages to our own mailbox +'hello' SEND ⎕self +(⍳2 2) SEND ⎕self + +⍝ Send a message to the double up thread +(⍳5) SEND id + +⍝ Check our own status again +⎕self ⎕tasks 0 1 4 + +⍝ We now have a few messages, but we want a specific one.. +⍝ That is, the one where the sender = id +{id=⊃⍵:1 ⍵ ⋄ 0} RECV 0 + +⍝ We might as well get the other messages as well +flush←{ + 12::⍵ ⍝ Stop when we get a timeout error + m←{1 ⍵} RECV 0 + ∇⍵,⊂m + } + +flush ⍬
\ No newline at end of file |