source: src/examples/thread.c @ ad6343e

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since ad6343e was 60819df7, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

Update thread example to add processors

  • Property mode set to 100644
File size: 948 bytes
Line 
1#line 1 "thread.c"
2#include <fstream>
3#include <kernel>
4#include <stdlib>
5#include <threads>
6
7// Start coroutine routines
8struct MyThread {
9        thread_h t;
10        unsigned id;
11        unsigned count;
12};
13
14DECL_THREAD(MyThread)
15
16void ?{}( MyThread * this ) {
17}
18
19void ?{}( MyThread * this, unsigned id, unsigned count ) {
20        this->id = id;
21        this->count = count;
22}
23
24void main(MyThread* this) {
25        sout | "Thread" | this->id | " : Suspending" | this->count | "times" | endl;
26        yield();
27
28        for(int i = 0; i < this->count; i++) {
29                sout | "Thread" | this->id | " : Suspend No." | i + 1 | endl;
30                yield();
31        }
32}
33
34int main(int argc, char* argv[]) {
35
36        unsigned itterations = 10u;
37        if(argc == 2) { 
38                int val = ato(argv[1]);
39                assert(val >= 0);
40                itterations = val;
41        }
42
43        sout | "User main begin" | endl;
44
45        {
46                processor p;
47                {
48                        thread(MyThread) thread1 = { 1u, itterations };
49                        thread(MyThread) thread2 = { 2u, itterations };
50                }
51        }
52
53        sout | "User main end" | endl;
54
55        return 0;
56}
Note: See TracBrowser for help on using the repository browser.