#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; int value; }; void ?{}( MyThread * this, int value ) { this->value = value; } void ^?{}( MyThread * this ) {} void co_main(MyThread* this) { printf("Main called with %p\n", this); printf("Thread value is %d\n", this->value); } thread_h* get_thread(MyThread* this) { return &this->t; } coroutine* get_coroutine(MyThread* this) { return &this->t.c; } void ?{}( MyThread * this ) { this->value = 1; printf("MyThread created\n"); printf("Address %p\n", this); printf("handle %p\n", get_thread(this)); printf("main %p\n", co_main); printf("get_t %p\n", get_thread); printf("invoke %p\n", CtxInvokeThread); } int main() { printf("Main is %p\n", this_coroutine()); printf("Creating thread\n"); thread(MyThread) thread1; printf("Main is %p\n", this_coroutine()); printf("First thread created\n"); kernel_run(); return 0; }