---
title: "ClikaRT::threading::ThreadPool"
sidebar_label: "ThreadPool"
description: "A handle to ClikaRT's thread pool. Get the process-wide pool with get_thread_pool(). The default ctor is hidden; handles only come from the factory. Copyable and cheap (shares the underlying pool)."
---

<!-- Generated by tools/doxygen2mdx from Doxygen XML. Do not edit. -->

<span class="api-kind api-kind--class">class</span>

**Header:** `ClikaRT/threading/threading.h`

[ClikaRT](../../index.md)'s thread pool: schedule background work, run parallel loops, and control or query the process-wide pool that [ClikaRT](../../index.md)'s compute runs on.

[ClikaRT](../../index.md) keeps one process-wide pool, sized to the host's physical cores by default (or `CLIKA_RT_NUM_THREADS`, see [`ClikaRT/common/env_vars.h`](../env/index.md#env_vars-h)). `parallel_for` / `schedule` run on it; `get_thread_pool()` hands back a handle to it. Its width is fixed when the pool is first created, so set `CLIKA_RT_NUM_THREADS` before the first compute to change it.

A handle to [ClikaRT](../../index.md)'s thread pool. Get the process-wide pool with `get_thread_pool()`. The default ctor is hidden; handles only come from the factory. Copyable and cheap (shares the underlying pool).

## Member functions

### schedule() {#schedule}

<div class="api-signature">

`void` **`schedule`**(`std::function<void()>` `work`) `const`

</div>

Fire-and-forget: enqueue `work` to run on a pool thread. Returns immediately; there is no completion signal (use a `std::promise`/future in `work` if you need to wait for it). A throw from `work` is contained in your own runtime and swallowed; fire-and-forget work has no error channel, and an unwind into a pool worker would terminate.

<div class="api-declared">

Declared in `ClikaRT/threading/threading.h`, line 43

</div>

### degree\_of\_parallelism() {#degree_of_parallelism}

<div class="api-signature">

`int` **`degree_of_parallelism`**() `const`

</div>

Number of worker threads (the degree of parallelism).

<div class="api-declared">

Declared in `ClikaRT/threading/threading.h`, line 64

</div>
