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 68e6031 was
c84e80a,
checked in by Thierry Delisle <tdelisle@…>, 8 years ago
|
Kernel now supports [0-9] cfa threads on a single core, using round-robin scheduling and no preemption
|
-
Property mode set to
100644
|
File size:
1.2 KB
|
Rev | Line | |
---|
[c49bf54] | 1 | #include <kernel> |
---|
| 2 | #include <stdlib> |
---|
| 3 | #include <threads> |
---|
| 4 | |
---|
| 5 | // Start coroutine routines |
---|
| 6 | extern "C" { |
---|
| 7 | forall(dtype T | is_coroutine(T)) |
---|
| 8 | void CtxInvokeCoroutine(T * this); |
---|
| 9 | |
---|
| 10 | forall(dtype T | is_coroutine(T)) |
---|
| 11 | void CtxStart(T * this, void ( *invoke)(T *)); |
---|
| 12 | |
---|
| 13 | forall(dtype T | is_coroutine(T)) |
---|
| 14 | void CtxInvokeThread(T * this); |
---|
| 15 | } |
---|
| 16 | |
---|
| 17 | struct MyThread { |
---|
| 18 | thread_h t; |
---|
[c84e80a] | 19 | unsigned id; |
---|
| 20 | unsigned count; |
---|
[c49bf54] | 21 | }; |
---|
| 22 | |
---|
[c84e80a] | 23 | void ?{}( MyThread * this ) { |
---|
| 24 | this->id = 0; |
---|
| 25 | this->count = 10; |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | void ?{}( MyThread * this, unsigned id, unsigned count ) { |
---|
| 29 | this->id = id; |
---|
| 30 | this->count = count; |
---|
[c49bf54] | 31 | } |
---|
| 32 | |
---|
| 33 | void ^?{}( MyThread * this ) {} |
---|
| 34 | |
---|
[7fbe450] | 35 | void main(MyThread* this) { |
---|
[c49bf54] | 36 | printf("Main called with %p\n", this); |
---|
[c84e80a] | 37 | printf("Thread %d : Suspending %d times\n", this->id, this->count); |
---|
| 38 | |
---|
| 39 | for(int i = 0; i < this->count; i++) { |
---|
| 40 | printf("Thread %d : Suspend No. %d\n", this->id, i + 1); |
---|
| 41 | printf("Back to %p\n", &this->t.c); |
---|
| 42 | suspend(); |
---|
| 43 | } |
---|
[c49bf54] | 44 | } |
---|
| 45 | |
---|
| 46 | thread_h* get_thread(MyThread* this) { |
---|
| 47 | return &this->t; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | coroutine* get_coroutine(MyThread* this) { |
---|
| 51 | return &this->t.c; |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | int main() { |
---|
| 55 | |
---|
| 56 | thread(MyThread) thread1; |
---|
[c84e80a] | 57 | thread(MyThread) thread2; |
---|
[c49bf54] | 58 | |
---|
[c84e80a] | 59 | thread2.handle.id = 1; |
---|
[c49bf54] | 60 | |
---|
[c84e80a] | 61 | printf("\n\nMain is %p\n", this_coroutine()); |
---|
[c49bf54] | 62 | |
---|
| 63 | kernel_run(); |
---|
| 64 | |
---|
[c84e80a] | 65 | printf("Kernel terminated correctly\n"); |
---|
| 66 | |
---|
[c49bf54] | 67 | return 0; |
---|
| 68 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.