ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change
on this file since e2ef6bf was
bcda04c,
checked in by Thierry Delisle <tdelisle@…>, 8 years ago
|
Fixed autogen constructors for concurrent sues
|
-
Property mode set to
100644
|
File size:
960 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 | |
---|
[ef42b143] | 12 | void increment( monitor_t * mutex p1, monitor_t * mutex p2, int * value ) { |
---|
[2781e65] | 13 | *value += 1; |
---|
| 14 | } |
---|
| 15 | |
---|
| 16 | struct MyThread { |
---|
[17af7d1] | 17 | thread_desc __thrd; |
---|
[2781e65] | 18 | int target; |
---|
| 19 | }; |
---|
| 20 | |
---|
| 21 | DECL_THREAD(MyThread); |
---|
| 22 | |
---|
| 23 | void ?{}( MyThread * this, int target ) { |
---|
| 24 | this->target = target; |
---|
| 25 | } |
---|
| 26 | |
---|
[cb0e6de] | 27 | void ^?{}( MyThread * mutex this ) {} |
---|
| 28 | |
---|
[2781e65] | 29 | void main( MyThread* this ) { |
---|
| 30 | for(int i = 0; i < 1000000; i++) { |
---|
| 31 | choose(this->target) { |
---|
| 32 | case 0: increment( &m1, &m2, &global12 ); |
---|
| 33 | case 1: increment( &m2, &m3, &global23 ); |
---|
| 34 | case 2: increment( &m1, &m3, &global13 ); |
---|
| 35 | } |
---|
| 36 | } |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | int main(int argc, char* argv[]) { |
---|
| 40 | processor p; |
---|
| 41 | { |
---|
| 42 | scoped(MyThread) * f[6]; |
---|
| 43 | for(int i = 0; i < 6; i++) { |
---|
| 44 | f[i] = ((scoped(MyThread) *)malloc()){ i % 3 }; |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | for(int i = 0; i < 6; i++) { |
---|
| 48 | delete( f[i] ); |
---|
| 49 | } |
---|
| 50 | } |
---|
| 51 | sout | global12 | global23 | global13 | endl; |
---|
| 52 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.