diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/demo/demo.odin | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/examples/demo/demo.odin b/examples/demo/demo.odin index 604d56695..67435f4ea 100644 --- a/examples/demo/demo.odin +++ b/examples/demo/demo.odin @@ -3,6 +3,7 @@ package main import "core:fmt" import "core:mem" import "core:os" +import "core:thread" import "core:reflect" import "intrinsics" @@ -1088,6 +1089,54 @@ parametric_polymorphism :: proc() { } +prefix_table := [?]string{ + "White", + "Red", + "Green", + "Blue", + "Octarine", + "Black", +}; + +threading_example :: proc() { + fmt.println("\n# threading_example"); + + worker_proc :: proc(t: ^thread.Thread) { + for iteration in 1..5 { + fmt.printf("Thread %d is on iteration %d\n", t.user_index, iteration); + fmt.printf("`%s`: iteration %d\n", prefix_table[t.user_index], iteration); + // win32.sleep(1); + } + } + + threads := make([dynamic]^thread.Thread, 0, len(prefix_table)); + defer delete(threads); + + for in prefix_table { + if t := thread.create(worker_proc); t != nil { + t.init_context = context; + t.use_init_context = true; + t.user_index = len(threads); + append(&threads, t); + thread.start(t); + } + } + + for len(threads) > 0 { + for i := 0; i < len(threads); /**/ { + if t := threads[i]; thread.is_done(t) { + fmt.printf("Thread %d is done\n", t.user_index); + thread.destroy(t); + + ordered_remove(&threads, i); + } else { + i += 1; + } + } + } +} + + array_programming :: proc() { fmt.println("\n# array programming"); { @@ -1783,7 +1832,10 @@ main :: proc() { ranged_fields_for_array_compound_literals(); deprecated_attribute(); range_statements_with_multiple_return_values(); - soa_struct_layout(); + threading_example(); + + // TODO(tetra): When bill fixes SOA array comparison to nil in reserve_soa, we can re-enable this. + // soa_struct_layout(); } } |