source:
src/examples/thread.c@
092528b
| Last change on this file since 092528b was bd98b58, checked in by , 9 years ago | |
|---|---|
|
|
| File size: 910 bytes | |
| Rev | Line | |
|---|---|---|
| [8f49a54] | 1 | #include <fstream> |
| [c49bf54] | 2 | #include <stdlib> |
| 3 | #include <threads> | |
| 4 | ||
| [8f49a54] | 5 | // Start coroutine routines |
| 6 | struct MyThread { | |
| 7 | thread_h t; | |
| 8 | unsigned id; | |
| 9 | unsigned count; | |
| 10 | }; | |
| [c49bf54] | 11 | |
| [bd98b58] | 12 | // DECL_THREAD(MyThread) |
| [c49bf54] | 13 | |
| [8f49a54] | 14 | void ?{}( MyThread * this, unsigned id, unsigned count ) { |
| 15 | this->id = id; | |
| 16 | this->count = count; | |
| 17 | } | |
| [c49bf54] | 18 | |
| [bd98b58] | 19 | // void main(MyThread* this) { |
| 20 | // sout | "Thread" | this->id | " : Suspending" | this->count | "times" | endl; | |
| 21 | // yield(); | |
| [c49bf54] | 22 | |
| [bd98b58] | 23 | // for(int i = 0; i < this->count; i++) { |
| 24 | // sout | "Thread" | this->id | " : Suspend No." | i + 1 | endl; | |
| 25 | // yield(); | |
| 26 | // } | |
| 27 | // } | |
| [c84e80a] | 28 | |
| [8f49a54] | 29 | int main(int argc, char* argv[]) { |
| [c49bf54] | 30 | |
| [bd98b58] | 31 | // unsigned itterations = 10u; |
| 32 | // if(argc == 2) { | |
| 33 | // int val = ato(argv[1]); | |
| 34 | // assert(val >= 0); | |
| 35 | // itterations = val; | |
| 36 | // } | |
| [c49bf54] | 37 | |
| [8f49a54] | 38 | sout | "User main begin" | endl; |
| [c84e80a] | 39 | |
| [bd98b58] | 40 | // { |
| 41 | // thread(MyThread) thread1 = { 1u, itterations }; | |
| 42 | // thread(MyThread) thread2 = { 2u, itterations }; | |
| 43 | // } | |
| [c49bf54] | 44 | |
| [8f49a54] | 45 | sout | "User main end" | endl; |
| [c84e80a] | 46 | |
| [c49bf54] | 47 | return 0; |
| 48 | } |
Note:
See TracBrowser
for help on using the repository browser.