ADTarm-ehast-experimentalcleanup-dtorsenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change
on this file since c4d80cb was
83a071f9,
checked in by Rob Schluntz <rschlunt@…>, 7 years ago
|
Fix concurrency library, tests, and keywords for references
|
-
Property mode set to
100644
|
File size:
977 bytes
|
Line | |
---|
1 | #include <fstream> |
---|
2 | #include <kernel> |
---|
3 | #include <monitor> |
---|
4 | #include <thread> |
---|
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.