source: src/examples/thread.c @ eb2e723

aaron-thesisarm-ehcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerresolv-newwith_gc
Last change on this file since eb2e723 was eb2e723, checked in by Thierry Delisle <tdelisle@…>, 5 years ago

First prototype of kernel with proper startup and shutdown, not yet implemented for i386

  • Property mode set to 100644
File size: 1.3 KB
Line 
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;
19//      unsigned id;
20//      unsigned count;
21// };
22
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;
31// }
32
33// void ^?{}( MyThread * this ) {}
34
35// void main(MyThread* this) {
36//      printf("Main called with %p\n", this);
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//      }
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
54int main() {
55        printf("Main is %p\n", this_coroutine());
56
57        // thread(MyThread) thread1;
58        // thread(MyThread) thread2;
59
60        // thread2.handle.id = 1;
61
62
63        // // kernel_run();
64
65        // printf("Kernel terminated correctly\n");
66
67        return 0;
68}
Note: See TracBrowser for help on using the repository browser.