1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- 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, 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, 64))
- client_allocator := mem.arena_allocator(&client_arena)
- //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("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)
- }
- /*
- 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
- */
|