ADTast-experimental
Last change
on this file since d964c39 was
fd54fef,
checked in by Michael Brooks <mlbrooks@…>, 4 years ago
|
Converting the project to use the new syntax for otype, dtype and ttytpe.
Changed prelude (gen), libcfa and test suite to use it. Added a simple deprecation rule of the old syntax to the parser; we might wish to support both syntaxes "officially," like with an extra CLI switch, but this measure should serve as a simple reminder for our team to try the new syntax.
|
-
Property mode set to
100644
|
File size:
1.2 KB
|
Line | |
---|
1 | #include <fstream.hfa> |
---|
2 | #include <kernel.hfa> |
---|
3 | #include <monitor.hfa> |
---|
4 | #include <thread.hfa> |
---|
5 | |
---|
6 | static int global12, global23, global13; |
---|
7 | |
---|
8 | monitor monitor_t {}; |
---|
9 | |
---|
10 | static monitor_t m1, m2, m3; |
---|
11 | |
---|
12 | void increment( monitor_t & mutex p1, monitor_t & mutex p2, int & value ) { |
---|
13 | assert(active_thread() == get_monitor(p1)->owner); |
---|
14 | assert(active_thread() == get_monitor(p2)->owner); |
---|
15 | value += 1; |
---|
16 | assert(active_thread() == get_monitor(p1)->owner); |
---|
17 | assert(active_thread() == get_monitor(p2)->owner); |
---|
18 | } |
---|
19 | |
---|
20 | thread MyThread { |
---|
21 | int target; |
---|
22 | }; |
---|
23 | |
---|
24 | void ?{}( MyThread & this, int target ) { |
---|
25 | this.target = target; |
---|
26 | } |
---|
27 | |
---|
28 | void ^?{}( MyThread & mutex this ) {} |
---|
29 | |
---|
30 | void main( MyThread & this ) { |
---|
31 | for(int i = 0; i < 1000000; i++) { |
---|
32 | choose(this.target) { |
---|
33 | case 0: increment( m1, m2, global12 ); |
---|
34 | case 1: increment( m2, m3, global23 ); |
---|
35 | case 2: increment( m1, m3, global13 ); |
---|
36 | } |
---|
37 | } |
---|
38 | } |
---|
39 | |
---|
40 | forall(T & | sized(T) | { void ^?{}(T & mutex); }) |
---|
41 | void delete_mutex(T * x) { |
---|
42 | ^(*x){}; |
---|
43 | free(x); |
---|
44 | } |
---|
45 | |
---|
46 | int main(int argc, char* argv[]) { |
---|
47 | processor p; |
---|
48 | { |
---|
49 | MyThread * f[6]; |
---|
50 | for(int i = 0; i < 6; i++) { |
---|
51 | f[i] = new(i % 3); |
---|
52 | } |
---|
53 | |
---|
54 | for(int i = 0; i < 6; i++) { |
---|
55 | delete_mutex( f[i] ); |
---|
56 | } |
---|
57 | } |
---|
58 | sout | global12 | global23 | global13; |
---|
59 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.