source: doc/theses/thierry_delisle_MMath/notes/cor-thread-traits.c @ 397edf7

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 397edf7 was 67982887, checked in by Peter A. Buhr <pabuhr@…>, 6 years ago

specialize thesis directory-names

  • Property mode set to 100644
File size: 2.0 KB
Line 
1//-----------------------------------------------------------------------------
2// Coroutine trait
3// Anything that implements this trait can be resumed.
4// Anything that is resumed is a coroutine.
5trait is_coroutine(dtype T) {
6      void main(T* this);
7      coroutine_handle* get_handle(T* this);
8}
9
10//-----------------------------------------------------------------------------
11forall(dtype T | {coroutine_handle* T.c})
12coroutine_handle* get_handle(T* this) {
13        return this->c
14}
15
16//-----------------------------------------------------------------------------
17struct myCoroutine {
18        int bla;
19        coroutine_handle c;
20};
21
22void main(myCoroutine* this) {
23        sout | this->bla | endl;
24}
25
26void foo() {
27        //Run the coroutine
28        myCoroutine myc;
29        resume(myc);
30}
31
32//-----------------------------------------------------------------------------
33// Thread trait
34// Alternative 1
35trait is_thread(dtype T) { 
36      void main(T* this);
37      thread_handle* get_handle(T* this);
38        thread T;
39};
40
41//-----------------------------------------------------------------------------
42forall(dtype T | {thread_handle* T.t})
43thread_handle* get_handle(T* this) {
44        return this->t
45}
46
47//-----------------------------------------------------------------------------
48thread myThread {
49        int bla;
50        thread_handle c;
51};
52
53void main(myThread* this) {
54        sout | this->bla | endl;
55}
56
57void foo() {
58        //Run the thread
59        myThread myc;
60}
61
62//-----------------------------------------------------------------------------
63// Thread trait
64// Alternative 2
65trait is_thread(dtype T) {
66      void main(T* this);
67      thread_handle* get_handle(T* this);
68       
69};
70
71//-----------------------------------------------------------------------------
72forall(dtype T | {thread_handle* T.t})
73thread_handle* get_handle(T* this) {
74        return this->t
75}
76
77//-----------------------------------------------------------------------------
78struct myThread {
79        int bla;
80        thread_handle c;
81};
82
83void main(myThread* this) {
84        sout | this->bla | endl;
85}
86
87void foo() {
88        //Run the thread
89        thread(myThread) myc;
90}
Note: See TracBrowser for help on using the repository browser.