Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/examples/thread.c

    rc84e80a rc49bf54  
    1717struct MyThread {
    1818        thread_h t;
    19         unsigned id;
    20         unsigned count;
     19        int value;
    2120};
    2221
    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;
     22void ?{}( MyThread * this, int value ) {
     23        this->value = value;
    3124}
    3225
    3326void ^?{}( MyThread * this ) {}
    3427
    35 void main(MyThread* this) {
     28void co_main(MyThread* this) {
    3629        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         }
     30        printf("Thread value is %d\n", this->value);
    4431}
    4532
     
    5239}
    5340
     41void ?{}( MyThread * this ) {
     42        this->value = 1;
     43        printf("MyThread created\n");
     44        printf("Address %p\n", this);
     45        printf("handle %p\n", get_thread(this));
     46        printf("main %p\n", co_main);
     47        printf("get_t %p\n", get_thread);
     48        printf("invoke %p\n", CtxInvokeThread);
     49}
     50
    5451int main() {
    5552
     53        printf("Main is %p\n", this_coroutine());
     54
     55        printf("Creating thread\n");
     56
    5657        thread(MyThread) thread1;
    57         thread(MyThread) thread2;
    5858
    59         thread2.handle.id = 1;
     59        printf("Main is %p\n", this_coroutine());       
    6060
    61         printf("\n\nMain is %p\n", this_coroutine());
     61        printf("First thread created\n");
    6262
    6363        kernel_run();
    6464
    65         printf("Kernel terminated correctly\n");
    66 
    6765        return 0;
    6866}
Note: See TracChangeset for help on using the changeset viewer.