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 8f49a54 was
8f49a54,
checked in by Thierry Delisle <tdelisle@…>, 8 years ago
|
Clean-up thread, kernel and examples
|
-
Property mode set to
100644
|
File size:
874 bytes
|
Line | |
---|
1 | #include <fstream> |
---|
2 | #include <stdlib> |
---|
3 | #include <threads> |
---|
4 | |
---|
5 | // Start coroutine routines |
---|
6 | struct MyThread { |
---|
7 | thread_h t; |
---|
8 | unsigned id; |
---|
9 | unsigned count; |
---|
10 | }; |
---|
11 | |
---|
12 | DECL_THREAD(MyThread) |
---|
13 | |
---|
14 | void ?{}( MyThread * this, unsigned id, unsigned count ) { |
---|
15 | this->id = id; |
---|
16 | this->count = count; |
---|
17 | } |
---|
18 | |
---|
19 | void main(MyThread* this) { |
---|
20 | sout | "Thread" | this->id | " : Suspending" | this->count | "times" | endl; |
---|
21 | suspend(); |
---|
22 | |
---|
23 | for(int i = 0; i < this->count; i++) { |
---|
24 | sout | "Thread" | this->id | " : Suspend No." | i + 1 | endl; |
---|
25 | suspend(); |
---|
26 | } |
---|
27 | } |
---|
28 | |
---|
29 | int main(int argc, char* argv[]) { |
---|
30 | |
---|
31 | unsigned itterations = 10; |
---|
32 | if(argc == 2) { |
---|
33 | int val = ato(argv[1]); |
---|
34 | assert(val >= 0); |
---|
35 | itterations = val; |
---|
36 | } |
---|
37 | |
---|
38 | sout | "User main begin" | endl; |
---|
39 | |
---|
40 | { |
---|
41 | thread(MyThread) thread1 = { (unsigned)1, itterations }; |
---|
42 | thread(MyThread) thread2 = { (unsigned)2, itterations }; |
---|
43 | } |
---|
44 | |
---|
45 | sout | "User main end" | endl; |
---|
46 | |
---|
47 | return 0; |
---|
48 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.