diff options
| author | gingerBill <bill@gingerbill.org> | 2022-03-31 11:55:46 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2022-03-31 11:55:46 +0100 |
| commit | 22b961ea53a1b9dfbc9218059b8473a0e52ae35c (patch) | |
| tree | 0e27bf001db0018e2f7412675d13027e53c08e86 /examples | |
| parent | 06e8476efc421a27ea8cd908cd5e6d8b319ebf0f (diff) | |
Update Thread Pool in `core:thread`
Thanks to the work of eisbehr
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/demo/demo.odin | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/examples/demo/demo.odin b/examples/demo/demo.odin index 9c2732cca..b3ce3ade9 100644 --- a/examples/demo/demo.odin +++ b/examples/demo/demo.odin @@ -1145,29 +1145,29 @@ threading_example :: proc() { } } - // { // Thread Pool - // fmt.println("\n## Thread Pool") - // task_proc :: proc(t: ^thread.Task) { - // index := t.user_index % len(prefix_table) - // for iteration in 1..=5 { - // fmt.printf("Worker Task %d is on iteration %d\n", t.user_index, iteration) - // fmt.printf("`%s`: iteration %d\n", prefix_table[index], iteration) - // time.sleep(1 * time.Millisecond) - // } - // } - - // pool: thread.Pool - // thread.pool_init(pool=&pool, thread_count=3) - // defer thread.pool_destroy(&pool) - - - // for i in 0..<30 { - // thread.pool_add_task(pool=&pool, procedure=task_proc, data=nil, user_index=i) - // } - - // thread.pool_start(&pool) - // thread.pool_wait_and_process(&pool) - // } + { // Thread Pool + fmt.println("\n## Thread Pool") + task_proc :: proc(t: thread.Task) { + index := t.user_index % len(prefix_table) + for iteration in 1..=5 { + fmt.printf("Worker Task %d is on iteration %d\n", t.user_index, iteration) + fmt.printf("`%s`: iteration %d\n", prefix_table[index], iteration) + time.sleep(1 * time.Millisecond) + } + } + + pool: thread.Pool + thread.pool_init(pool=&pool, thread_count=3, allocator=context.allocator) + defer thread.pool_destroy(&pool) + + + for i in 0..<30 { + thread.pool_add_task(pool=&pool, procedure=task_proc, data=nil, user_index=i) + } + + thread.pool_start(&pool) + thread.pool_finish(&pool) + } } |