source: CIVL/examples/languageFeatures/atomicStatement.cvl@ d410676

1.23 2.0 main test-branch
Last change on this file since d410676 was d410676, checked in by Manchun Zheng <zmanchun@…>, 12 years ago

Add warning when atomic block is too long, and throw exception when non-determinism in atomic is detected, add tests accordingly.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@345 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 653 bytes
Line 
1int n = 3;
2void foo(){
3 int k = n;
4 k = k + 1;
5}
6
7void main(){
8 int i = 0;
9 int x = 3;
10
11 $atomic{
12
13 if(i < 0)
14 i = 1;
15 else
16 i = 2;
17 }
18
19 $assert i == 2;
20
21 $atomic
22 if(i > 0)
23 i = 1;
24 else
25 i = 2;
26
27 $assert i == 1;
28
29 $atomic{
30 i = 2;
31 switch(i){
32 case 1: i = 2;
33 case 2: i = 3;break;
34 default: i = 5;
35 }
36 }
37
38 $assert i == 3;
39
40 $atomic{
41 i = 0;
42 for(int j = 0; j < 10; j++){
43 i += j;
44 }
45 }
46
47 $assert i == 45;
48
49 $atomic{
50 for(int m = 0; m < 5; m++){
51 $spawn foo();
52 }
53 }
54
55 //nested atomic and non-pure-local atomic block
56 $atomic{
57 n = 0;
58 n += 1;
59 $atomic{
60 i+=2;
61 i += 3; }
62 n += 9;
63 }
64
65 $assert n == 10;
66}
Note: See TracBrowser for help on using the repository browser.