diff options
| author | steven-na <noreply.github@stvnc.dev> | 2026-08-15 21:12:11 -0700 |
|---|---|---|
| committer | steven-na <noreply.github@stvnc.dev> | 2026-08-15 21:12:11 -0700 |
| commit | 82e164f8796d57aa78c14b20f0a750f4b40c861b (patch) | |
| tree | 1eb0df74a98ddc3fa872084b02ba309b3b0fb314 /src/threadpool.h | |
| parent | a4e71241ffbcc8576cd42856db061bb366cec3e5 (diff) | |
Threadpool timeout
Diffstat (limited to 'src/threadpool.h')
| -rw-r--r-- | src/threadpool.h | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/threadpool.h b/src/threadpool.h index b009008..190f971 100644 --- a/src/threadpool.h +++ b/src/threadpool.h @@ -14,13 +14,15 @@ typedef struct { // Threads check this before waiting for a job b32 is_running; // Write mutex for num_active/alive -pthread_mutex_t * count_mtx; +pthread_mutex_t * access_mtx; // Signal to tp_wait that all jobs are complete pthread_cond_t *done_signal; // Threads currently doing a job u64 num_active; // Threads who are alive u64 num_alive; +// Forceful teardown status + b32 is_abandoned; // Job queue ts_deque_t jobs; } thread_pool_t; @@ -30,7 +32,12 @@ thread_pool_t *tp_create(smrt_arena_t * arena , u64 max_jobs , u64 num_threads); -i32 tp_destroy(thread_pool_t *tp); +// Pass INT32_MAX for infinite timeout +// May return ETIMEDOUT, in which case, +// *tp should not be deallocaed until +// the program exits. +i32 tp_destroy(thread_pool_t *tp , + i32 timeout ); i32 tp_push_job(thread_pool_t * tp , tp_job_proc job , |