ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprno_listpersistent-indexerpthread-emulationqualifiedEnum
Last change
on this file since a5121bf was
73abe95,
checked in by Thierry Delisle <tdelisle@…>, 6 years ago
|
Replace extension-less headers with .hfa
|
-
Property mode set to
100644
|
File size:
993 bytes
|
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 | value += 1; |
---|
14 | } |
---|
15 | |
---|
16 | thread MyThread { |
---|
17 | int target; |
---|
18 | }; |
---|
19 | |
---|
20 | void ?{}( MyThread & this, int target ) { |
---|
21 | this.target = target; |
---|
22 | } |
---|
23 | |
---|
24 | void ^?{}( MyThread & mutex this ) {} |
---|
25 | |
---|
26 | void main( MyThread & this ) { |
---|
27 | for(int i = 0; i < 1000000; i++) { |
---|
28 | choose(this.target) { |
---|
29 | case 0: increment( m1, m2, global12 ); |
---|
30 | case 1: increment( m2, m3, global23 ); |
---|
31 | case 2: increment( m1, m3, global13 ); |
---|
32 | } |
---|
33 | } |
---|
34 | } |
---|
35 | |
---|
36 | forall(dtype T | sized(T) | { void ^?{}(T & mutex); }) |
---|
37 | void delete_mutex(T * x) { |
---|
38 | ^(*x){}; |
---|
39 | free(x); |
---|
40 | } |
---|
41 | |
---|
42 | int main(int argc, char* argv[]) { |
---|
43 | processor p; |
---|
44 | { |
---|
45 | MyThread * f[6]; |
---|
46 | for(int i = 0; i < 6; i++) { |
---|
47 | f[i] = new(i % 3); |
---|
48 | } |
---|
49 | |
---|
50 | for(int i = 0; i < 6; i++) { |
---|
51 | delete_mutex( f[i] ); |
---|
52 | } |
---|
53 | } |
---|
54 | sout | global12 | global23 | global13 | endl; |
---|
55 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.