|
@@ -4,29 +4,55 @@ package main
|
|
|
import "core:fmt"
|
|
|
import "core:thread"
|
|
|
import "core:sync"
|
|
|
+import "core:time"
|
|
|
import "core:mem"
|
|
|
|
|
|
|
|
|
+fact :: proc(n: u64) -> u64{
|
|
|
+ return fact_h(n, 1)
|
|
|
+}
|
|
|
+
|
|
|
+fact_h :: proc(n: u64, a: u64) -> u64{
|
|
|
+ if n == 0{
|
|
|
+ return a
|
|
|
+ }else{
|
|
|
+ return fact_h(n - 1, n * a)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
main :: proc(){
|
|
|
wg : sync.Wait_Group
|
|
|
|
|
|
threadPool :thread.Pool
|
|
|
- thread.pool_init(&threadPool, context.allocator, 5)
|
|
|
+ //thread.pool_init(&threadPool, context.allocator, 5)
|
|
|
+ thread.pool_init(&threadPool, context.allocator, 30_000)
|
|
|
thread.pool_start(&threadPool)
|
|
|
defer thread.pool_destroy(&threadPool)
|
|
|
|
|
|
client_arena :mem.Arena
|
|
|
- mem.arena_init(&client_arena, make([]u8, 1024))
|
|
|
+ //mem.arena_init(&client_arena, make([]u8, 1024))
|
|
|
+ mem.arena_init(&client_arena, make([]u8, 64))
|
|
|
client_allocator := mem.arena_allocator(&client_arena)
|
|
|
- for i := 0; i < 5; i+=1{
|
|
|
+ //for i := 0; i < 5; i += 1 {
|
|
|
+ for i := 0; i < 30_000; i += 1 {
|
|
|
thread.pool_add_task(&threadPool, client_allocator, worker, &{}, i)
|
|
|
}
|
|
|
thread.pool_finish(&threadPool)
|
|
|
- fmt.println("End")
|
|
|
+ fmt.println("The End")
|
|
|
}
|
|
|
|
|
|
worker :: proc (t: thread.Task){
|
|
|
fmt.printf("working on thread %d\n", t.user_index)
|
|
|
+ //time.sleep(time.Second)
|
|
|
+ v20: u64
|
|
|
+ for {
|
|
|
+ time.sleep(3 * time.Second)
|
|
|
+ //v20 := fact(20)
|
|
|
+ v20 = fact(20)
|
|
|
+ fmt.printf("worker = %d fact 20 = %d\n", t.user_index, v20)
|
|
|
+ }
|
|
|
+ fmt.printf("worker finish %d\n", t.user_index)
|
|
|
}
|
|
|
|
|
|
|