Changeset 60819df7


Ignore:
Timestamp:
Jan 24, 2017, 11:45:35 AM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
2cdf6dc
Parents:
8def349
Message:

Update thread example to add processors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/examples/thread.c

    r8def349 r60819df7  
     1#line 1 "thread.c"
    12#include <fstream>
     3#include <kernel>
    24#include <stdlib>
    35#include <threads>
     
    1012};
    1113
    12 // DECL_THREAD(MyThread)
     14DECL_THREAD(MyThread)
     15
     16void ?{}( MyThread * this ) {
     17}
    1318
    1419void ?{}( MyThread * this, unsigned id, unsigned count ) {
     
    1722}
    1823
    19 // void main(MyThread* this) {
    20 //      sout | "Thread" | this->id | " : Suspending" | this->count | "times" | endl;
    21 //      yield();
     24void main(MyThread* this) {
     25        sout | "Thread" | this->id | " : Suspending" | this->count | "times" | endl;
     26        yield();
    2227
    23 //      for(int i = 0; i < this->count; i++) {
    24 //              sout | "Thread" | this->id | " : Suspend No." | i + 1 | endl;
    25 //              yield();
    26 //      }
    27 // }
     28        for(int i = 0; i < this->count; i++) {
     29                sout | "Thread" | this->id | " : Suspend No." | i + 1 | endl;
     30                yield();
     31        }
     32}
    2833
    2934int main(int argc, char* argv[]) {
    3035
    31         // unsigned itterations = 10u;
    32         // if(argc == 2) {
    33         //      int val = ato(argv[1]);
    34         //      assert(val >= 0);
    35         //      itterations = val;
    36         // }
     36        unsigned itterations = 10u;
     37        if(argc == 2) {
     38                int val = ato(argv[1]);
     39                assert(val >= 0);
     40                itterations = val;
     41        }
    3742
    3843        sout | "User main begin" | endl;
    3944
    40         // {
    41         //      thread(MyThread) thread1 = { 1u, itterations };
    42         //      thread(MyThread) thread2 = { 2u, itterations };
    43         // }
     45        {
     46                processor p;
     47                {
     48                        thread(MyThread) thread1 = { 1u, itterations };
     49                        thread(MyThread) thread2 = { 2u, itterations };
     50                }
     51        }
    4452
    4553        sout | "User main end" | endl;
Note: See TracChangeset for help on using the changeset viewer.