Changes in src/examples/thread.c [c84e80a:c49bf54]
- File:
-
- 1 edited
-
src/examples/thread.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/examples/thread.c
rc84e80a rc49bf54 17 17 struct MyThread { 18 18 thread_h t; 19 unsigned id; 20 unsigned count; 19 int value; 21 20 }; 22 21 23 void ?{}( MyThread * this ) { 24 this->id = 0; 25 this->count = 10; 26 } 27 28 void ?{}( MyThread * this, unsigned id, unsigned count ) { 29 this->id = id; 30 this->count = count; 22 void ?{}( MyThread * this, int value ) { 23 this->value = value; 31 24 } 32 25 33 26 void ^?{}( MyThread * this ) {} 34 27 35 void main(MyThread* this) {28 void co_main(MyThread* this) { 36 29 printf("Main called with %p\n", this); 37 printf("Thread %d : Suspending %d times\n", this->id, this->count); 38 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 } 30 printf("Thread value is %d\n", this->value); 44 31 } 45 32 … … 52 39 } 53 40 41 void ?{}( 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", co_main); 47 printf("get_t %p\n", get_thread); 48 printf("invoke %p\n", CtxInvokeThread); 49 } 50 54 51 int main() { 55 52 53 printf("Main is %p\n", this_coroutine()); 54 55 printf("Creating thread\n"); 56 56 57 thread(MyThread) thread1; 57 thread(MyThread) thread2;58 58 59 thread2.handle.id = 1;59 printf("Main is %p\n", this_coroutine()); 60 60 61 printf(" \n\nMain is %p\n", this_coroutine());61 printf("First thread created\n"); 62 62 63 63 kernel_run(); 64 64 65 printf("Kernel terminated correctly\n");66 67 65 return 0; 68 66 }
Note:
See TracChangeset
for help on using the changeset viewer.