Internal changes; thread.odin for windows only

This commit is contained in:
Ginger Bill
2017-07-20 23:57:56 +01:00
parent 401a5955a4
commit dbddec33c8
8 changed files with 245 additions and 62 deletions

View File

@@ -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;
}
}
}
}