source: src/examples/thread.c@ dcb42b8

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 stuck-waitfor-destruct with_gc
Last change on this file since dcb42b8 was dcb42b8, checked in by Thierry Delisle <tdelisle@…>, 9 years ago

Some more cleaning and commenting the kernel

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