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 7c70089 was 17af7d1, checked in by Thierry Delisle <tdelisle@…>, 9 years ago |
Some clean-up of runtime code
|
-
Property mode
set to
100644
|
File size:
1008 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 |
|
---|
[ef42b143] | 8 | struct monitor_t {
|
---|
| 9 | monitor_desc m;
|
---|
| 10 | };
|
---|
| 11 |
|
---|
| 12 | monitor_desc * get_monitor( monitor_t * this ) {
|
---|
| 13 | return &this->m;
|
---|
| 14 | }
|
---|
| 15 |
|
---|
| 16 | static monitor_t m1, m2, m3;
|
---|
[2781e65] | 17 |
|
---|
[ef42b143] | 18 | void increment( monitor_t * mutex p1, monitor_t * mutex p2, int * value ) {
|
---|
[2781e65] | 19 | *value += 1;
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | struct MyThread {
|
---|
[17af7d1] | 23 | thread_desc __thrd;
|
---|
[2781e65] | 24 | int target;
|
---|
| 25 | };
|
---|
| 26 |
|
---|
| 27 | DECL_THREAD(MyThread);
|
---|
| 28 |
|
---|
| 29 | void ?{}( MyThread * this, int target ) {
|
---|
| 30 | this->target = target;
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | void main( MyThread* this ) {
|
---|
| 34 | for(int i = 0; i < 1000000; i++) {
|
---|
| 35 | choose(this->target) {
|
---|
| 36 | case 0: increment( &m1, &m2, &global12 );
|
---|
| 37 | case 1: increment( &m2, &m3, &global23 );
|
---|
| 38 | case 2: increment( &m1, &m3, &global13 );
|
---|
| 39 | }
|
---|
| 40 | }
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | int main(int argc, char* argv[]) {
|
---|
| 44 | processor p;
|
---|
| 45 | {
|
---|
| 46 | scoped(MyThread) * f[6];
|
---|
| 47 | for(int i = 0; i < 6; i++) {
|
---|
| 48 | f[i] = ((scoped(MyThread) *)malloc()){ i % 3 };
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | for(int i = 0; i < 6; i++) {
|
---|
| 52 | delete( f[i] );
|
---|
| 53 | }
|
---|
| 54 | }
|
---|
| 55 | sout | global12 | global23 | global13 | endl;
|
---|
| 56 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.