File tree Expand file tree Collapse file tree 2 files changed +63
-14
lines changed Expand file tree Collapse file tree 2 files changed +63
-14
lines changed Original file line number Diff line number Diff line change @@ -209,40 +209,48 @@ obtained with the option `--property`.
209
209
210
210
### Unbounded Loops
211
211
212
- CBMC can also be used for programs with unbounded loops. In this case,
213
- CBMC is used for bug hunting only; CBMC does not attempt to find all
214
- bugs. The following program (lock-example.c) is an example of a program
215
- with a user-specified property:
212
+ CBMC can also be used for programs with unbounded loops. In this case, CBMC
213
+ is used for bug hunting only; CBMC does not attempt to find all bugs. The
214
+ following program
215
+ ([ lock-example.c] ( https://raw.githubusercontent.com/diffblue/cbmc/develop/doc/cprover-manual/lock-example.c ) )
216
+ is an example of a program with a user-specified property:
216
217
217
218
``` C
218
219
_Bool nondet_bool ();
219
220
_Bool LOCK = 0 ;
220
221
221
- _Bool lock () {
222
- if(nondet_bool()) {
222
+ _Bool lock ()
223
+ {
224
+ if(nondet_bool())
225
+ {
223
226
assert(!LOCK);
224
- LOCK=1;
225
- return 1; }
227
+ LOCK = 1;
228
+ return 1;
229
+ }
226
230
227
231
return 0;
228
232
}
229
233
230
- void unlock () {
234
+ void unlock ()
235
+ {
231
236
assert (LOCK);
232
- LOCK= 0;
237
+ LOCK = 0;
233
238
}
234
239
235
- int main () {
240
+ int main ()
241
+ {
236
242
unsigned got_lock = 0;
237
243
int times;
238
244
239
- while(times > 0) {
240
- if(lock()) {
245
+ while(times > 0)
246
+ {
247
+ if(lock())
248
+ {
241
249
got_lock++;
242
250
/* critical section * /
243
251
}
244
252
245
- if(got_lock!= 0)
253
+ if(got_lock != 0)
246
254
unlock ();
247
255
248
256
got_lock--;
Original file line number Diff line number Diff line change
1
+ _Bool nondet_bool ();
2
+ _Bool LOCK = 0 ;
3
+
4
+ _Bool lock ()
5
+ {
6
+ if (nondet_bool ())
7
+ {
8
+ assert (!LOCK );
9
+ LOCK = 1 ;
10
+ return 1 ;
11
+ }
12
+
13
+ return 0 ;
14
+ }
15
+
16
+ void unlock ()
17
+ {
18
+ assert (LOCK );
19
+ LOCK = 0 ;
20
+ }
21
+
22
+ int main ()
23
+ {
24
+ unsigned got_lock = 0 ;
25
+ int times ;
26
+
27
+ while (times > 0 )
28
+ {
29
+ if (lock ())
30
+ {
31
+ got_lock ++ ;
32
+ /* critical section */
33
+ }
34
+
35
+ if (got_lock != 0 )
36
+ unlock ();
37
+
38
+ got_lock -- ;
39
+ times -- ;
40
+ }
41
+ }
You can’t perform that action at this time.
0 commit comments