source: src/examples/thread.c @ dcb42b8

aaron-thesisarm-ehcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerresolv-newwith_gc
Last change on this file since dcb42b8 was dcb42b8, checked in by Thierry Delisle <tdelisle@…>, 5 years ago

Some more cleaning and commenting the kernel

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