#include #include #include // Start coroutine routines extern "C" { forall(dtype T | is_coroutine(T)) void CtxInvokeCoroutine(T * this); forall(dtype T | is_coroutine(T)) void CtxStart(T * this, void ( *invoke)(T *)); forall(dtype T | is_coroutine(T)) void CtxInvokeThread(T * this); } struct MyThread { thread_h t; unsigned id; unsigned count; }; void ?{}( MyThread * this ) { this->id = 0; this->count = 10; } void ?{}( MyThread * this, unsigned id, unsigned count ) { this->id = id; this->count = count; } void ^?{}( MyThread * this ) {} void main(MyThread* this) { printf("Main called with %p\n", this); printf("Thread %d : Suspending %d times\n", this->id, this->count); for(int i = 0; i < this->count; i++) { printf("Thread %d : Suspend No. %d\n", this->id, i + 1); printf("Back to %p\n", &this->t.c); suspend(); } } thread_h* get_thread(MyThread* this) { return &this->t; } coroutine* get_coroutine(MyThread* this) { return &this->t.c; } int main() { thread(MyThread) thread1; thread(MyThread) thread2; thread2.handle.id = 1; printf("\n\nMain is %p\n", this_coroutine()); kernel_run(); printf("Kernel terminated correctly\n"); return 0; }