File tree Expand file tree Collapse file tree 1 file changed +66
-0
lines changed Expand file tree Collapse file tree 1 file changed +66
-0
lines changed Original file line number Diff line number Diff line change @@ -92,6 +92,71 @@ let guard5 () =
92
92
42 );
93
93
]
94
94
95
+ let f b n =
96
+ Run. first_or_terminate
97
+ [
98
+ (fun () ->
99
+ Control. terminate_unless
100
+ (let i = ref 0 in
101
+ while ! i < n do
102
+ i := ! i + 1 ;
103
+ Control. yield ()
104
+ done ;
105
+ true );
106
+ b);
107
+ (fun () ->
108
+ Control. terminate_unless
109
+ (let j = ref 0 in
110
+ while ! j < n do
111
+ j := ! j + 1 ;
112
+ Control. yield ()
113
+ done ;
114
+ false );
115
+ false );
116
+ ]
117
+
118
+ let demo () =
119
+ Run. first_or_terminate
120
+ [
121
+ (fun () ->
122
+ Control. terminate_unless (f false 1000 );
123
+ 17 );
124
+ (fun () ->
125
+ Control. terminate_unless (f false 80000 );
126
+ 11 );
127
+ (fun () ->
128
+ Control. terminate_unless
129
+ (while true do
130
+ Control. yield ()
131
+ done ;
132
+ true );
133
+ 27 );
134
+ (fun () ->
135
+ Control. terminate_unless
136
+ (Run. first_or_terminate
137
+ [
138
+ (fun () ->
139
+ Control. terminate_unless (f false 100000 );
140
+ false );
141
+ (fun () ->
142
+ Control. terminate_unless (f true 200000 );
143
+ true );
144
+ ]);
145
+ 42 );
146
+ (fun () ->
147
+ Control. terminate_unless
148
+ (Run. first_or_terminate
149
+ [
150
+ (fun () ->
151
+ Control. terminate_unless (f true 100 );
152
+ false );
153
+ (fun () ->
154
+ Control. terminate_unless (f false 10 );
155
+ false );
156
+ ]);
157
+ 13 );
158
+ ]
159
+
95
160
let () =
96
161
(* We use the test scheduler here, but in more practical use cases one should
97
162
likely use e.g. the multififo or the random scheduler to compute with
@@ -107,5 +172,6 @@ let () =
107
172
if 42 <> guard4 () then
108
173
print_endline " Guard 4 wasn't 42, but that is a known issue." );
109
174
(fun () -> assert (42 = guard5 () ));
175
+ (fun () -> assert (42 = demo () ));
110
176
];
111
177
print_endline " Ran guarded case statement examples."
You can’t perform that action at this time.
0 commit comments