source: src/examples/thread.c @ c0aa336

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 c0aa336 was e15df4c, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Renamed thread to scoped and thread_h to thread

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