source: doc/proposals/concurrency/notes/cor-thread-traits.c@ 38ac6ec

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since 38ac6ec was db0fa7c, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

Moved files and did some cleanup in the directories

  • Property mode set to 100644
File size: 2.0 KB
RevLine 
[f7ff3fb]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.