thr5.odin 968 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package main
  2. import "core:fmt"
  3. import "core:thread"
  4. import "core:sync"
  5. import "core:mem"
  6. main :: proc(){
  7. wg : sync.Wait_Group
  8. threadPool :thread.Pool
  9. thread.pool_init(&threadPool, context.allocator, 5)
  10. thread.pool_start(&threadPool)
  11. defer thread.pool_destroy(&threadPool)
  12. client_arena :mem.Arena
  13. mem.arena_init(&client_arena, make([]u8, 1024))
  14. client_allocator := mem.arena_allocator(&client_arena)
  15. for i := 0; i < 5; i+=1{
  16. thread.pool_add_task(&threadPool, client_allocator, worker, &{}, i)
  17. }
  18. thread.pool_finish(&threadPool)
  19. fmt.println("End")
  20. }
  21. worker :: proc (t: thread.Task){
  22. fmt.printf("working on thread %d\n", t.user_index)
  23. }
  24. /*
  25. make o thr5
  26. odin run thr5.odin -file
  27. working on thread 1
  28. working on thread 0
  29. working on thread 4
  30. working on thread 3
  31. working on thread 2
  32. End
  33. make o thr5
  34. odin run thr5.odin -file
  35. working on thread 0
  36. working on thread 1
  37. working on thread 2
  38. working on thread 3
  39. working on thread 4
  40. End
  41. */