source: src/examples/thread.c@ c2416d5

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

First prototype of kernel with proper startup and shutdown, not yet implemented for i386

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