Skip to content

Commit 2429e16

Browse files
Add todo items outlining how thread resource delegation can be implemented.
1 parent b9ee37a commit 2429e16

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/threadpool.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,17 @@ API_FUNC __attribute__((no_sanitize("memory"))) void hw_pool_destroy() {
382382
atomic_store_explicit(&hw_pool.num_threads, 0, memory_order_release);
383383
}
384384

385+
// TODO: If no thread pool is owned, have a thread run the function directly.
386+
387+
// TODO: interface for querying about the owned thread pool.
388+
// At least let the user get the number of threads available.
389+
// If no thread pool is owned, just report a single thread.
390+
391+
// TODO: have the main thread fill the role of thread 0.
392+
// Instead of having the main thread wait/resume, swap in its thread-locals
393+
// then have it run the per-thread function.
394+
// This will avoid the suspend/resume OS overheads for at least that thread.
395+
385396
API_FUNC void
386397
pool_run_on_all(pool_header *pool, qt_threadpool_func_type func, void *arg) {
387398
uint32_t num_threads =
@@ -412,3 +423,20 @@ API_FUNC void hw_pool_run_on_all(qt_threadpool_func_type func, void *arg) {
412423
pool_run_on_all(&hw_pool, func, arg);
413424
}
414425

426+
API_FUNC void divide_pool(uint32_t num_groups, ...) {
427+
// TODO: for each group:
428+
// make a new threadpool header for the group
429+
// wake the leader thread and have it:
430+
// update its own thread-local thread pool and index
431+
// re-wake and launch a new iteration loop on its delegated worker
432+
// threads, having them:
433+
// update their thread-local indices then launch their own iteration
434+
// loops
435+
// wait for the other threads in the group to finish (busy or futex?)
436+
// restore its own thread-locals
437+
// signal completion to main via the atomic on the outer pool
438+
// have the main thread act as leader for the first group
439+
// wait for the groups to finish (busy or futex?)
440+
;
441+
}
442+

0 commit comments

Comments
 (0)