diff options
| author | Ginger Bill <bill@gingerbill.org> | 2017-07-20 23:57:56 +0100 |
|---|---|---|
| committer | Ginger Bill <bill@gingerbill.org> | 2017-07-20 23:57:56 +0100 |
| commit | dbddec33c8247beb5984d0c3fbcdf86a94054248 (patch) | |
| tree | 6f711915422e3a2b76013d4bf6d488ce1221d84e /code | |
| parent | 401a5955a4ed1746e96f29db8e521cb4831a863d (diff) | |
Internal changes; thread.odin for windows only
Diffstat (limited to 'code')
| -rw-r--r-- | code/demo.odin | 61 |
1 files changed, 54 insertions, 7 deletions
diff --git a/code/demo.odin b/code/demo.odin index 912168306..9f47eb1d9 100644 --- a/code/demo.odin +++ b/code/demo.odin @@ -1,11 +1,58 @@ -import "fmt.odin"; -import "strconv.odin"; +import ( + "fmt.odin"; + "strconv.odin"; + "thread.odin"; + win32 "sys/windows.odin"; +) -Opaque :: union{}; +prefix_table := [...]string{ + "White", + "Red", + "Orange", + "Yellow", + "Green", + "Blue", + "Octarine", + "Black", +}; -main :: proc() { - buf := make([]u8, 0, 10); - s := strconv.append_bool(buf, true); - fmt.println(s); +worker_proc :: proc(t: ^thread.Thread) -> int { + do_work :: proc(iteration: int, index: int) { + fmt.printf("`%s`: iteration %d\n", prefix_table[index], iteration); + win32.sleep(1); + } + + for iteration in 1...5 { + fmt.printf("Thread %d is on iteration %d\n", t.user_index, iteration); + do_work(iteration, t.user_index); + } + return 0; } + +main :: proc() { + threads := make([]^thread.Thread, 0, len(prefix_table)); + + for i in 0..len(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); i += 1 { + if t := threads[i]; thread.is_done(t) { + fmt.printf("Thread %d is done\n", t.user_index); + thread.destroy(t); + + threads[i] = threads[len(threads)-1]; + pop(&threads); + i -= 1; + } + } + } +} |