equal
deleted
inserted
replaced
21 |
21 |
22 s1 := ReadWriteStream on:(Array new:1000). |
22 s1 := ReadWriteStream on:(Array new:1000). |
23 s2 := ReadWriteStream on:(Array new:1000). |
23 s2 := ReadWriteStream on:(Array new:1000). |
24 |
24 |
25 p1 := [ |
25 p1 := [ |
26 [ |
26 [ |
27 s1 nextPut:q next |
27 s1 nextPut:q next |
28 ] loop. |
28 ] loop. |
29 ] fork. |
29 ] fork. |
30 |
30 |
31 p2 := [ |
31 p2 := [ |
32 [ |
32 [ |
33 s2 nextPut:q next |
33 s2 nextPut:q next |
34 ] loop. |
34 ] loop. |
35 ] fork. |
35 ] fork. |
36 |
36 |
37 1 to:1000 do:[:i| |
37 1 to:1000 do:[:i| |
38 q nextPut:i |
38 q nextPut:i |
39 ]. |
39 ]. |
40 |
40 |
41 Delay waitForMilliseconds:20. |
41 Delay waitForMilliseconds:20. |
42 |
42 |
43 p1 terminate. |
43 p1 terminate. |
50 |
50 |
51 next1 := s1 next. |
51 next1 := s1 next. |
52 next2 := s2 next. |
52 next2 := s2 next. |
53 |
53 |
54 1 to: 1000 do:[:i| |
54 1 to: 1000 do:[:i| |
55 self should:[ |
55 self should:[ |
56 next1 == i ifTrue:[ |
56 next1 == i ifTrue:[ |
57 next1 := s1 next. |
57 next1 := s1 next. |
58 true. |
58 true. |
59 ] ifFalse:[ |
59 ] ifFalse:[ |
60 next2 == i ifTrue:[ |
60 next2 == i ifTrue:[ |
61 next2 := s2 next. |
61 next2 := s2 next. |
62 true |
62 true |
63 ]. |
63 ]. |
64 ] |
64 ] |
65 ] |
65 ] |
66 ]. |
66 ]. |
67 ! |
67 ! |
68 |
68 |
69 test2ReadersAndWriters |
69 test2ReadersAndWriters |
70 |
70 |
75 |
75 |
76 s1 := ReadWriteStream on:(Array new:20000). |
76 s1 := ReadWriteStream on:(Array new:20000). |
77 s2 := ReadWriteStream on:(Array new:20000). |
77 s2 := ReadWriteStream on:(Array new:20000). |
78 |
78 |
79 p1 := [ |
79 p1 := [ |
80 [ |
80 [ |
81 s1 nextPut:q next |
81 s1 nextPut:q next |
82 ] loop. |
82 ] loop. |
83 ] fork. |
83 ] fork. |
84 |
84 |
85 p2 := [ |
85 p2 := [ |
86 [ |
86 [ |
87 s2 nextPut:q next |
87 s2 nextPut:q next |
88 ] loop. |
88 ] loop. |
89 ] fork. |
89 ] fork. |
90 |
90 |
91 pw := [ |
91 pw := [ |
92 1 to:10000 do:[:i| |
92 1 to:10000 do:[:i| |
93 q nextPut:i+scale |
93 q nextPut:i+scale |
94 ]. |
94 ]. |
95 ] fork. |
95 ] fork. |
96 |
96 |
97 1 to:10000 do:[:i| |
97 1 to:10000 do:[:i| |
98 q nextPut:i |
98 q nextPut:i |
99 ]. |
99 ]. |
100 |
100 |
101 pw waitUntilTerminated. |
101 pw waitUntilTerminated. |
102 Delay waitForMilliseconds:20. |
102 Delay waitForMilliseconds:20. |
103 |
103 |
109 s1 reset. |
109 s1 reset. |
110 s2 reset. |
110 s2 reset. |
111 |
111 |
112 next1 := next2 := 0. |
112 next1 := next2 := 0. |
113 self should:[ |
113 self should:[ |
114 s1 contents conform:[:i| |
114 s1 contents conform:[:i| |
115 i < scale ifTrue:[ |
115 i < scale ifTrue:[ |
116 next1 < i and:[next1 := i. true] |
116 next1 < i and:[next1 := i. true] |
117 ] ifFalse:[ |
117 ] ifFalse:[ |
118 next2 < i and:[next2 := i. true] |
118 next2 < i and:[next2 := i. true] |
119 ]. |
119 ]. |
120 ]. |
120 ]. |
121 ]. |
121 ]. |
122 next1 := next2 := 0. |
122 next1 := next2 := 0. |
123 self should:[ |
123 self should:[ |
124 s2 contents conform:[:i| |
124 s2 contents conform:[:i| |
125 i < scale ifTrue:[ |
125 i < scale ifTrue:[ |
126 next1 < i and:[next1 := i. true] |
126 next1 < i and:[next1 := i. true] |
127 ] ifFalse:[ |
127 ] ifFalse:[ |
128 next2 < i and:[next2 := i. true] |
128 next2 < i and:[next2 := i. true] |
129 ]. |
129 ]. |
130 ]. |
130 ]. |
131 ]. |
131 ]. |
132 |
132 |
133 s1 reset. |
133 s1 reset. |
134 s2 reset. |
134 s2 reset. |
135 |
135 |
136 all := SortedCollection new:20000. |
136 all := SortedCollection new:20000. |
137 all addAll:s1 contents. |
137 all addAll:s1 contents. |
138 all addAll:s2 contents. |
138 all addAll:s2 contents. |
139 |
139 |
140 1 to: 10000 do:[:i| |
140 1 to: 10000 do:[:i| |
141 self assert:((all at:i) == i). |
141 self assert:((all at:i) == i). |
142 self assert:((all at:(i+10000)) == (i+scale)). |
142 self assert:((all at:(i+10000)) == (i+scale)). |
143 ]. |
143 ]. |
144 ! |
144 ! |
145 |
145 |
146 test2Writers |
146 test2Writers |
147 |
147 |