source: CIVL/examples/languageFeatures/atomicStatement.cvl@ 9705dfd

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

implement atomic statements, supporting nested atomic statements. TODO: 1. throw an exception when non-determinism is encountered at runtime; 2. report an error when a wait statement is encountered.

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

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