ADT
aaron-thesis
arm-eh
ast-experimental
cleanup-dtors
deferred_resn
demangler
enum
forall-pointer-decay
jacob/cs343-translation
jenkins-sandbox
new-ast
new-ast-unique-expr
new-env
no_list
persistent-indexer
pthread-emulation
qualifiedEnum
resolv-new
with_gc
Last change
on this file since 1fbab5a was 348006f, checked in by Thierry Delisle <tdelisle@…>, 9 years ago |
Renamed thread to thread_desc
|
-
Property mode
set to
100644
|
File size:
981 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 |
|
---|
[84c52a8] | 8 | static monitor_desc m1, m2, m3;
|
---|
[2781e65] | 9 |
|
---|
[84c52a8] | 10 | void increment( /*mutex*/ monitor_desc * p1, /*mutex*/ monitor_desc * p2, int * value ) {
|
---|
| 11 | monitor_desc * mons[] = { p1, p2 };
|
---|
[2781e65] | 12 | monitor_guard_t g = { mons, 2 };
|
---|
| 13 | *value += 1;
|
---|
| 14 | }
|
---|
| 15 |
|
---|
| 16 | struct MyThread {
|
---|
[348006f] | 17 | thread_desc t;
|
---|
[2781e65] | 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.