Skip to content

Commit 520e035

Browse files
committed
v.h: v_threadpool: Default n_threads to system ncpu + 1
Since the threadpool can now access v_sys_get_cores(), might as well make use of it.
1 parent 19f9f4d commit 520e035

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

include/v.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ void *v_thread_wait_and_destroy(v_thread *);
228228
struct v_threadpool;
229229
typedef struct v_threadpool v_threadpool;
230230

231+
/* NOTE: n_threads == 0 will default to system ncpu + 1 */
231232
v_threadpool *v_threadpool_create(size_t n_threads);
232233
void v_threadpool_destroy(v_threadpool *);
233234

@@ -839,7 +840,7 @@ static void *v_threadpool_worker(void *arg) {
839840

840841
v_threadpool *v_threadpool_create(size_t n_threads) {
841842
if (!n_threads)
842-
n_threads = 2;
843+
n_threads = v_sys_get_cores() + 1;
843844
struct v_threadpool *pool = calloc(1, sizeof(*pool));
844845
pool->alive_threads = n_threads;
845846
pool->mutex = v_mutex_create();

0 commit comments

Comments
 (0)