Changeset 8f49a54 for src/examples


Ignore:
Timestamp:
Jan 19, 2017, 3:42:29 PM (8 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:
dcb42b8
Parents:
4a3386b4
Message:

Clean-up thread, kernel and examples

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/examples/thread.c

    r4a3386b4 r8f49a54  
    1 // #include <kernel>
     1#include <fstream>
    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
     6struct MyThread {
     7        thread_h t;
     8        unsigned id;
     9        unsigned count;
     10};
    911
    10 //       forall(dtype T | is_coroutine(T))
    11 //       void CtxStart(T * this, void ( *invoke)(T *));
     12DECL_THREAD(MyThread)
    1213
    13 //      forall(dtype T | is_coroutine(T))
    14 //       void CtxInvokeThread(T * this);
    15 // }
     14void ?{}( MyThread * this, unsigned id, unsigned count ) {
     15        this->id = id;
     16        this->count = count;
     17}
    1618
    17 // struct MyThread {
    18 //      thread_h t;
    19 //      unsigned id;
    20 //      unsigned count;
    21 // };
     19void main(MyThread* this) {
     20        sout | "Thread" | this->id | " : Suspending" | this->count | "times" | endl;
     21        suspend();
    2222
    23 // void ?{}( MyThread * this ) {
    24 //      this->id = 0;
    25 //      this->count = 10;
    26 // }
     23        for(int i = 0; i < this->count; i++) {
     24                sout | "Thread" | this->id | " : Suspend No." | i + 1 | endl;
     25                suspend();
     26        }
     27}
    2728
    28 // void ?{}( MyThread * this, unsigned id, unsigned count ) {
    29 //      this->id = id;
    30 //      this->count = count;
    31 // }
     29int main(int argc, char* argv[]) {
    3230
    33 // void ^?{}( MyThread * this ) {}
     31        unsigned itterations = 10;
     32        if(argc == 2) {
     33                int val = ato(argv[1]);
     34                assert(val >= 0);
     35                itterations = val;
     36        }
    3437
    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        sout | "User main begin" | endl;
    3839
    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 // }
     40        {
     41                thread(MyThread) thread1 = { (unsigned)1, itterations };
     42                thread(MyThread) thread2 = { (unsigned)2, itterations };
     43        }
    4544
    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 
    54 int 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");
     45        sout | "User main end" | endl;
    6646
    6747        return 0;
Note: See TracChangeset for help on using the changeset viewer.