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