source: src/examples/thread.c@ a362f97

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

Renamed thread to scoped and thread_h to thread

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