summaryrefslogtreecommitdiff
path: root/demos/chain.apl
blob: 89e7830fc8daa7503a2ac4dc57dfd231c4680679 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
⍝ First we define a function which recieves a message msg,
⍝ and sends (1+msg) to the task with id ⍵
f←{
        (from msg)←{1 ⍵}⍇⍬
        (1+msg)⍈⍵
      }

⍝ Now start 1000 of those
⊢last←f&'chain'⍣1000 ⊢ ⎕self

⍝ Verify that over 1000 threads are running
≢⎕THREADS 0

⍝ Start the chain by sending something to the last one,
⍝ and wait for a result
run←{
        _←⍵⍈last
        {1 (2⊃⍵)}⍇⍬
      }
run 0 ⍝ Run it!

⎕threads 0 1 2