source: CIVL/examples/languageFeatures/atomStatement.cvl@ 38b7d06

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

Implement $atomic and $atom blocks. Tests are added accordingly. TODO: implement related methods in TransientProcessState.java.

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

  • Property mode set to 100644
File size: 639 bytes
RevLine 
[10e8759]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 $atom{
12
13 if(i < 0)
14 i = 1;
15 else
16 i = 2;
17 }
18
19 $assert i == 2;
20
21 $atom
22 if(i > 0)
23 i = 1;
24 else
25 i = 2;
26
27 $assert i == 1;
28
29 $atom{
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 $atom{
41 i = 0;
42 for(int j = 0; j < 10; j++){
43 i += j;
44 }
45 }
46
47 $assert i == 45;
48
49 $atom{
50 for(int m = 0; m < 5; m++){
51 $spawn foo();
52 }
53 }
54
55 //nested atomic and non-pure-local atomic block
56 $atom{
57 n = 0;
58 n += 1;
59 $atom{
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.