|
@@ -0,0 +1,54 @@
|
|
|
+
|
|
|
+package main
|
|
|
+
|
|
|
+import "core:fmt"
|
|
|
+import "core:thread"
|
|
|
+import "core:sync"
|
|
|
+import "core:mem"
|
|
|
+
|
|
|
+
|
|
|
+main :: proc(){
|
|
|
+ wg : sync.Wait_Group
|
|
|
+
|
|
|
+ threadPool :thread.Pool
|
|
|
+ thread.pool_init(&threadPool, context.allocator, 5)
|
|
|
+ thread.pool_start(&threadPool)
|
|
|
+ defer thread.pool_destroy(&threadPool)
|
|
|
+
|
|
|
+ client_arena :mem.Arena
|
|
|
+ mem.arena_init(&client_arena, make([]u8, 1024))
|
|
|
+ client_allocator := mem.arena_allocator(&client_arena)
|
|
|
+ for i := 0; i < 5; i+=1{
|
|
|
+ thread.pool_add_task(&threadPool, client_allocator, worker, &{}, i)
|
|
|
+ }
|
|
|
+ thread.pool_finish(&threadPool)
|
|
|
+ fmt.println("End")
|
|
|
+}
|
|
|
+
|
|
|
+worker :: proc (t: thread.Task){
|
|
|
+ fmt.printf("working on thread %d\n", t.user_index)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/*
|
|
|
+
|
|
|
+make o thr5
|
|
|
+odin run thr5.odin -file
|
|
|
+working on thread 1
|
|
|
+working on thread 0
|
|
|
+working on thread 4
|
|
|
+working on thread 3
|
|
|
+working on thread 2
|
|
|
+End
|
|
|
+
|
|
|
+make o thr5
|
|
|
+odin run thr5.odin -file
|
|
|
+working on thread 0
|
|
|
+working on thread 1
|
|
|
+working on thread 2
|
|
|
+working on thread 3
|
|
|
+working on thread 4
|
|
|
+End
|
|
|
+
|
|
|
+*/
|
|
|
+
|