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