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 14a33790 was
348006f,
checked in by Thierry Delisle <tdelisle@…>, 7 years ago
|
Renamed thread to thread_desc
|
-
Property mode set to
100644
|
File size:
981 bytes
|
Line | |
---|
1 | #include <fstream> |
---|
2 | #include <kernel> |
---|
3 | #include <monitor> |
---|
4 | #include <thread> |
---|
5 | |
---|
6 | static int global12, global23, global13; |
---|
7 | |
---|
8 | static monitor_desc m1, m2, m3; |
---|
9 | |
---|
10 | void increment( /*mutex*/ monitor_desc * p1, /*mutex*/ monitor_desc * p2, int * value ) { |
---|
11 | monitor_desc * mons[] = { p1, p2 }; |
---|
12 | monitor_guard_t g = { mons, 2 }; |
---|
13 | *value += 1; |
---|
14 | } |
---|
15 | |
---|
16 | struct MyThread { |
---|
17 | thread_desc t; |
---|
18 | int target; |
---|
19 | }; |
---|
20 | |
---|
21 | DECL_THREAD(MyThread); |
---|
22 | |
---|
23 | void ?{}( MyThread * this, int target ) { |
---|
24 | this->target = target; |
---|
25 | } |
---|
26 | |
---|
27 | void main( MyThread* this ) { |
---|
28 | for(int i = 0; i < 1000000; i++) { |
---|
29 | choose(this->target) { |
---|
30 | case 0: increment( &m1, &m2, &global12 ); |
---|
31 | case 1: increment( &m2, &m3, &global23 ); |
---|
32 | case 2: increment( &m1, &m3, &global13 ); |
---|
33 | } |
---|
34 | } |
---|
35 | } |
---|
36 | |
---|
37 | int main(int argc, char* argv[]) { |
---|
38 | processor p; |
---|
39 | { |
---|
40 | scoped(MyThread) * f[6]; |
---|
41 | for(int i = 0; i < 6; i++) { |
---|
42 | f[i] = ((scoped(MyThread) *)malloc()){ i % 3 }; |
---|
43 | } |
---|
44 | |
---|
45 | for(int i = 0; i < 6; i++) { |
---|
46 | delete( f[i] ); |
---|
47 | } |
---|
48 | } |
---|
49 | sout | global12 | global23 | global13 | endl; |
---|
50 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.