Debian Codegraph @

demo/extqueue.rexx

raw
1 #!/usr/bin/env regina
2 /*
3 * This program tests the external queue interface of Regina
4 * It runs num_clients instances of itself, each instance will create a
5 * named queued. For even numbered instances, lines will be queued
6 * FIFO; odd numbered instances will be queued LIFO.
7 * Once each instance queues its lines, it will read lines off
8 * another stack; created by its opposite instance.
9 * Opposite instances are eg. instance 1 and num_clients, 2 and 48, etc
10 */
11 Trace o
12 parse source sys env prog
13 Select
14 When sys = 'WIN32' | sys = 'WIN64' Then
15 Do
16 prefix = 'start /b'
17 suffix = ''
18 End
19 When sys = 'UNIX' Then
20 Do
21 prefix = ''
22 suffix = '&'
23 End
24 Otherwise
25 Do
26 Say 'This demo will not run on this machine.'
27 Exit 1
28 End
29 End
30
31 num_clients = 50 /* 50 */
32 num_lines = 10 /* 100 */
33 If Arg() = 0 Then
34 Do
35 cmd = "rexx"
36 if stream( "./rexx", "C", "FSTAT" ) \= "" then
37 cmd = "./rexx"
38 if stream( "../rexx", "C", "FSTAT" ) \= "" then
39 cmd = "../rexx"
40 Do i = 1 To num_clients
41 Address System cmd prefix prog i suffix
42 End
43 End
44 Else
45 Do
46 /*
47 * Set up the list of opposites...
48 */
49 Do i = 1 To num_clients
50 opposite.i = 1+(num_clients-i)
51 End
52 Parse Arg instance
53 say instance
54 If instance // 2 = 0 Then order = 'fifo'
55 Else order = 'lifo'
56 call RxQueue 'Set', Rxqueue('Create', 'QUEUE'instance'@')
57 /* Say '***Creating queue' Rxqueue('Create', 'QUEUE'instance'@' ) */
58 /*
59 * push or queue num_lines lines onto our queue
60 */
61 Do i = 1 To num_lines
62 line = 'line'i 'from instance' instance
63 /* Say '***Going to put <'line'> on queue:' order */
64 If order = 'fifo' Then Queue line
65 Else Push line
66 End
67 /*
68 * Sleep for 10 seconds, then find our opposite, and
69 * set our default queue to its queue, and read off
70 * the the lines, checking they are in the correct
71 * order and the correct contents
72 */
73 Call Sleep(10)
74 /*
75 Say '***Setting queue. Previous was:' rxqueue('Set', 'QUEUE'opposite.instance'@' )
76 Say '***Getting queue. Now:' rxqueue('Get')
77 */
78 Call rxqueue 'Set', 'QUEUE'opposite.instance'@'
79 /*
80 * The order of the lines is the opposite to
81 * the order in which we put our lines on our queue
82 */
83 If order = 'lifo' Then
84 Do
85 /*
86 * PULL the lines off the stack, and check them
87 * they should be in FIFO order,
88 */
89 Do i = 1 To num_lines
90 Parse Pull line
91 exp = 'line'i 'from instance' opposite.instance
92 If line \= exp Then Call Abort line, exp
93 End
94 End
95 Else
96 Do
97 /*
98 * PULL the lines off the stack, and check them
99 * they should be in LIFO order,
100 */
101 Do i = num_lines To 1 By -1
102 Parse Pull line
103 exp = 'line'i 'from instance' opposite.instance
104 If line \= exp Then Call Abort line, exp
105 End
106 End
107 /*
108 * Cleanup up our opposite's queue
109 */
110 Call Rxqueue 'Delete', 'QUEUE'opposite.instance'@'
111 Say 'Instance' instance 'finished.'
112 End
113 Return 0
114
115 Abort: Procedure Expose instance
116 Parse Arg line, exp
117 say '--------------------------------------------------------------------'
118 Say 'Error validating instance' instance'. Got <'line'> Expecting <'exp'>'
119 Call Rxqueue 'Delete', 'QUEUE'opposite.instance'@'
120 say '--------------------------------------------------------------------'
121 Exit 1