ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumwith_gc
Last change
on this file since 13e8427 was
557435e,
checked in by Thierry Delisle <tdelisle@…>, 7 years ago
|
Moved concurrent objects
|
-
Property mode set to
100644
|
File size:
977 bytes
|
Rev | Line | |
---|
[2781e65] | 1 | #include <fstream> |
---|
| 2 | #include <kernel> |
---|
| 3 | #include <monitor> |
---|
[4a3334cf] | 4 | #include <thread> |
---|
[2781e65] | 5 | |
---|
| 6 | static int global12, global23, global13; |
---|
| 7 | |
---|
[bcda04c] | 8 | monitor monitor_t {}; |
---|
[ef42b143] | 9 | |
---|
| 10 | static monitor_t m1, m2, m3; |
---|
[2781e65] | 11 | |
---|
[83a071f9] | 12 | void increment( monitor_t & mutex p1, monitor_t & mutex p2, int & value ) { |
---|
| 13 | value += 1; |
---|
[2781e65] | 14 | } |
---|
| 15 | |
---|
[83a071f9] | 16 | thread MyThread { |
---|
[2781e65] | 17 | int target; |
---|
| 18 | }; |
---|
| 19 | |
---|
[00e80b6] | 20 | void ?{}( MyThread & this, int target ) { |
---|
| 21 | this.target = target; |
---|
[2781e65] | 22 | } |
---|
| 23 | |
---|
[00e80b6] | 24 | void ^?{}( MyThread & mutex this ) {} |
---|
[cb0e6de] | 25 | |
---|
[83a071f9] | 26 | void main( MyThread & this ) { |
---|
[2781e65] | 27 | for(int i = 0; i < 1000000; i++) { |
---|
[83a071f9] | 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 ); |
---|
[2781e65] | 32 | } |
---|
| 33 | } |
---|
| 34 | } |
---|
| 35 | |
---|
[83a071f9] | 36 | forall(dtype T | sized(T) | { void ^?{}(T & mutex); }) |
---|
| 37 | void delete_mutex(T * x) { |
---|
| 38 | ^(*x){}; |
---|
| 39 | free(x); |
---|
| 40 | } |
---|
| 41 | |
---|
[2781e65] | 42 | int main(int argc, char* argv[]) { |
---|
| 43 | processor p; |
---|
| 44 | { |
---|
[83a071f9] | 45 | MyThread * f[6]; |
---|
[2781e65] | 46 | for(int i = 0; i < 6; i++) { |
---|
[83a071f9] | 47 | f[i] = new(i % 3); |
---|
[2781e65] | 48 | } |
---|
| 49 | |
---|
| 50 | for(int i = 0; i < 6; i++) { |
---|
[83a071f9] | 51 | delete_mutex( f[i] ); |
---|
[2781e65] | 52 | } |
---|
| 53 | } |
---|
| 54 | sout | global12 | global23 | global13 | endl; |
---|
[00e80b6] | 55 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.