development-curl is a virtual target
[AROS-Contrib.git] / regina / demo / extqueue.rexx
blob1b1da514af0ec9df5e6062df28f72e81f9d27a31
1 /*
2 * This program tests the external queue interface of Regina
3 * It runs num_clients instances of itself, each instance will create a
4 * named queued. For even numbered instances, lines will be queued
5 * FIFO; odd numbered instances will be queued LIFO.
6 * Once each instance queues its lines, it will read lines off
7 * another stack; created by its opposite instance.
8 * Opposite instances are eg. instance 1 and num_clients, 2 and 48, etc
9 */
10 Trace o
11 parse source sys env prog
12 num_clients = 50 /* 50 */
13 num_lines = 10 /* 100 */
14 If Arg() = 0 Then
16 cmd = "rexx"
17 if stream( "./rexx", "C", "FSTAT" ) \= "" then
18 cmd = "./rexx"
19 if stream( "../rexx", "C", "FSTAT" ) \= "" then
20 cmd = "../rexx"
21 Do i = 1 To num_clients
22 Address System cmd prog i '&'
23 End
24 End
25 Else
28 * Set up the list of opposites...
30 Do i = 1 To num_clients
31 opposite.i = 1+(num_clients-i)
32 End
33 Parse Arg instance
34 say instance
35 If instance // 2 = 0 Then order = 'fifo'
36 Else order = 'lifo'
37 call RxQueue 'Set', Rxqueue('Create', 'QUEUE'instance'@')
38 /* Say '***Creating queue' Rxqueue('Create', 'QUEUE'instance'@' ) */
40 * push or queue num_lines lines onto our queue
42 Do i = 1 To num_lines
43 line = 'line'i 'from instance' instance
44 /* Say '***Going to put <'line'> on queue:' order */
45 If order = 'fifo' Then Queue line
46 Else Push line
47 End
49 * Sleep for 10 seconds, then find our opposite, and
50 * set our default queue to its queue, and read off
51 * the the lines, checking they are in the correct
52 * order and the correct contents
54 Call Sleep(10)
56 Say '***Setting queue. Previous was:' rxqueue('Set', 'QUEUE'opposite.instance'@' )
57 Say '***Getting queue. Now:' rxqueue('Get')
59 Call rxqueue 'Set', 'QUEUE'opposite.instance'@'
61 * The order of the lines is the opposite to
62 * the order in which we put our lines on our queue
64 If order = 'lifo' Then
67 * PULL the lines off the stack, and check them
68 * they should be in FIFO order,
70 Do i = 1 To num_lines
71 Parse Pull line
72 exp = 'line'i 'from instance' opposite.instance
73 If line \= exp Then Call Abort line, exp
74 End
75 End
76 Else
79 * PULL the lines off the stack, and check them
80 * they should be in LIFO order,
82 Do i = num_lines To 1 By -1
83 Parse Pull line
84 exp = 'line'i 'from instance' opposite.instance
85 If line \= exp Then Call Abort line, exp
86 End
87 End
89 * Cleanup up our opposite's queue
91 Call Rxqueue 'Delete', 'QUEUE'opposite.instance'@'
92 Say 'Instance' instance 'finished.'
93 End
94 Return 0
96 Abort: Procedure Expose instance
97 Parse Arg line, exp
98 say '--------------------------------------------------------------------'
99 Say 'Error validating instance' instance'. Got <'line'> Expecting <'exp'>'
100 Call Rxqueue 'Delete', 'QUEUE'opposite.instance'@'
101 say '--------------------------------------------------------------------'
102 Exit 1