source: src/examples/thread.c@ 7fbe450

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

No longer using co_main for coroutines/threads, now simply using main

  • Property mode set to 100644
File size: 1.2 KB
Line 
1#include <kernel>
2#include <stdlib>
3#include <threads>
4
5// Start coroutine routines
6extern "C" {
7 forall(dtype T | is_coroutine(T))
8 void CtxInvokeCoroutine(T * this);
9
10 forall(dtype T | is_coroutine(T))
11 void CtxStart(T * this, void ( *invoke)(T *));
12
13 forall(dtype T | is_coroutine(T))
14 void CtxInvokeThread(T * this);
15}
16
17struct MyThread {
18 thread_h t;
19 int value;
20};
21
22void ?{}( MyThread * this, int value ) {
23 this->value = value;
24}
25
26void ^?{}( MyThread * this ) {}
27
28void main(MyThread* this) {
29 printf("Main called with %p\n", this);
30 printf("Thread value is %d\n", this->value);
31}
32
33thread_h* get_thread(MyThread* this) {
34 return &this->t;
35}
36
37coroutine* get_coroutine(MyThread* this) {
38 return &this->t.c;
39}
40
41void ?{}( MyThread * this ) {
42 this->value = 1;
43 printf("MyThread created\n");
44 printf("Address %p\n", this);
45 printf("handle %p\n", get_thread(this));
46 printf("main %p\n", main);
47 printf("get_t %p\n", get_thread);
48 printf("invoke %p\n", CtxInvokeThread);
49}
50
51int main() {
52
53 printf("Main is %p\n", this_coroutine());
54
55 printf("Creating thread\n");
56
57 thread(MyThread) thread1;
58
59 printf("Main is %p\n", this_coroutine());
60
61 printf("First thread created\n");
62
63 kernel_run();
64
65 return 0;
66}
Note: See TracBrowser for help on using the repository browser.