Ignore:
Timestamp:
Jan 18, 2017, 6:12:13 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
aaron-thesis, arm-eh, 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, resolv-new, with_gc
Children:
68e6031
Parents:
7fbe450
Message:

Kernel now supports [0-9] cfa threads on a single core, using round-robin scheduling and no preemption

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/examples/thread.c

    r7fbe450 rc84e80a  
    1717struct MyThread {
    1818        thread_h t;
    19         int value;
     19        unsigned id;
     20        unsigned count;
    2021};
    2122
    22 void ?{}( MyThread * this, int value ) {
    23         this->value = value;
     23void ?{}( MyThread * this ) {
     24        this->id = 0;
     25        this->count = 10;
     26}
     27
     28void ?{}( MyThread * this, unsigned id, unsigned count ) {
     29        this->id = id;
     30        this->count = count;
    2431}
    2532
     
    2835void main(MyThread* this) {
    2936        printf("Main called with %p\n", this);
    30         printf("Thread value is %d\n", this->value);
     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        }
    3144}
    3245
     
    3952}
    4053
    41 void ?{}( 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", main);
    47         printf("get_t %p\n", get_thread);
    48         printf("invoke %p\n", CtxInvokeThread);
    49 }
    50 
    5154int main() {
    5255
    53         printf("Main is %p\n", this_coroutine());
     56        thread(MyThread) thread1;
     57        thread(MyThread) thread2;
    5458
    55         printf("Creating thread\n");
     59        thread2.handle.id = 1;
    5660
    57         thread(MyThread) thread1;
    58 
    59         printf("Main is %p\n", this_coroutine());
    60 
    61         printf("First thread created\n");
     61        printf("\n\nMain is %p\n", this_coroutine());
    6262
    6363        kernel_run();
    6464
     65        printf("Kernel terminated correctly\n");
     66
    6567        return 0;
    6668}
Note: See TracChangeset for help on using the changeset viewer.