Changeset eb2e723 for src/examples


Ignore:
Timestamp:
Jan 19, 2017, 2:42:49 PM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
35dd180f
Parents:
2175062
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/examples/thread.c

    r2175062 reb2e723  
    1 #include <kernel>
     1// #include <kernel>
    22#include <stdlib>
    33#include <threads>
    44
    5 // Start coroutine routines
    6 extern "C" {
    7       forall(dtype T | is_coroutine(T))
    8       void CtxInvokeCoroutine(T * this);
     5// // Start coroutine routines
     6// extern "C" {
     7//       forall(dtype T | is_coroutine(T))
     8//       void CtxInvokeCoroutine(T * this);
    99
    10       forall(dtype T | is_coroutine(T))
    11       void CtxStart(T * this, void ( *invoke)(T *));
     10//       forall(dtype T | is_coroutine(T))
     11//       void CtxStart(T * this, void ( *invoke)(T *));
    1212
    13         forall(dtype T | is_coroutine(T))
    14       void CtxInvokeThread(T * this);
    15 }
     13//      forall(dtype T | is_coroutine(T))
     14//       void CtxInvokeThread(T * this);
     15// }
    1616
    17 struct MyThread {
    18         thread_h t;
    19         unsigned id;
    20         unsigned count;
    21 };
     17// struct MyThread {
     18//      thread_h t;
     19//      unsigned id;
     20//      unsigned count;
     21// };
    2222
    23 void ?{}( MyThread * this ) {
    24         this->id = 0;
    25         this->count = 10;
    26 }
     23// void ?{}( MyThread * this ) {
     24//      this->id = 0;
     25//      this->count = 10;
     26// }
    2727
    28 void ?{}( MyThread * this, unsigned id, unsigned count ) {
    29         this->id = id;
    30         this->count = count;
    31 }
     28// void ?{}( MyThread * this, unsigned id, unsigned count ) {
     29//      this->id = id;
     30//      this->count = count;
     31// }
    3232
    33 void ^?{}( MyThread * this ) {}
     33// void ^?{}( MyThread * this ) {}
    3434
    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);
     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);
    3838
    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 }
     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// }
    4545
    46 thread_h* get_thread(MyThread* this) {
    47         return &this->t;
    48 }
     46// thread_h* get_thread(MyThread* this) {
     47//      return &this->t;
     48// }
    4949
    50 coroutine* get_coroutine(MyThread* this) {
    51         return &this->t.c;
    52 }
     50// coroutine* get_coroutine(MyThread* this) {
     51//      return &this->t.c;
     52// }
    5353
    5454int main() {
     55        printf("Main is %p\n", this_coroutine());
    5556
    56         thread(MyThread) thread1;
    57         thread(MyThread) thread2;
     57        // thread(MyThread) thread1;
     58        // thread(MyThread) thread2;
    5859
    59         thread2.handle.id = 1;
     60        // thread2.handle.id = 1;
    6061
    61         printf("\n\nMain is %p\n", this_coroutine());
    6262
    63         kernel_run();
     63        // // kernel_run();
    6464
    65         printf("Kernel terminated correctly\n");
     65        // printf("Kernel terminated correctly\n");
    6666
    6767        return 0;
Note: See TracChangeset for help on using the changeset viewer.