Changeset c84e80a for src/examples
- Timestamp:
- Jan 18, 2017, 6:12:13 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 68e6031
- Parents:
- 7fbe450
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/examples/thread.c ¶
r7fbe450 rc84e80a 17 17 struct MyThread { 18 18 thread_h t; 19 int value; 19 unsigned id; 20 unsigned count; 20 21 }; 21 22 22 void ?{}( MyThread * this, int value ) { 23 this->value = value; 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; 24 31 } 25 32 … … 28 35 void main(MyThread* this) { 29 36 printf("Main called with %p\n", this); 30 printf("Thread value is %d\n", this->value); 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 } 31 44 } 32 45 … … 39 52 } 40 53 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", main);47 printf("get_t %p\n", get_thread);48 printf("invoke %p\n", CtxInvokeThread);49 }50 51 54 int main() { 52 55 53 printf("Main is %p\n", this_coroutine()); 56 thread(MyThread) thread1; 57 thread(MyThread) thread2; 54 58 55 printf("Creating thread\n");59 thread2.handle.id = 1; 56 60 57 thread(MyThread) thread1; 58 59 printf("Main is %p\n", this_coroutine()); 60 61 printf("First thread created\n"); 61 printf("\n\nMain is %p\n", this_coroutine()); 62 62 63 63 kernel_run(); 64 64 65 printf("Kernel terminated correctly\n"); 66 65 67 return 0; 66 68 }
Note: See TracChangeset
for help on using the changeset viewer.