---
title: "ClikaRT::threading"
sidebar_label: "threading"
description: "Namespace ClikaRT::threading"
---

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

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

## Classes

| Name | Description |
| --- | --- |
| [`ThreadPool`](./ThreadPool.md) | 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). |

## Functions

### get\_thread\_pool() {#get_thread_pool}

<div class="api-signature">

[`ThreadPool`](./ThreadPool.md) **`get_thread_pool`**()

</div>

The process-wide thread pool that [ClikaRT](../../index.md)'s compute runs on. Declared before the class so the in-class friend declaration is a redeclaration of an already-exported function (a friend cannot carry the export marker, and adding it only on a later declaration is ill-formed on PE).

<div class="api-declared">

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

</div>

### parallel\_for() {#parallel_for}

<div class="api-signature">

`void` **`parallel_for`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::int64_t` `begin`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::int64_t` `end`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::int64_t` `grain`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::function<void(std::int64_t begin, std::int64_t end)>` `body`<br />
)

</div>

<div class="api-declared">

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

</div>

### schedule() {#schedule}

<div class="api-signature">

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

</div>

Fire-and-forget work on the process-wide pool (convenience for [`get_thread_pool()`](./index.md#get_thread_pool)`.schedule(work)`). Same containment contract as [`ThreadPool::schedule`](./ThreadPool.md#schedule).

<div class="api-declared">

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

</div>

### num\_threads() {#num_threads}

<div class="api-signature">

`unsigned` **`num_threads`**()

</div>

The process-wide pool's PARTICIPANT count: the calling thread plus the pool's workers, which is the number of cores a parallel operator keeps busy. Configure it with the `CLIKA_RT_NUM_THREADS` environment variable (read when the pool is first created); it defaults to the host's physical-core count (its Performance-core count on a hybrid SoC).

<div class="api-declared">

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

</div>

### set\_spinning\_allowed() {#set_spinning_allowed}

<div class="api-signature">

`void` **`set_spinning_allowed`**(`bool` `allowed`)

</div>

Whether the runtime's idle threads keep spinning for a while before they sleep (on by default). A serving loop's gaps between operations are short, and a sleeping thread's wake costs tens of microseconds on a server and up to a millisecond or more on a phone, so spinning keeps a generation's steps at their pace, the way ONNX Runtime's `session.intra_op.allow_spinning` and Intel OpenMP's `KMP_BLOCKTIME` do. Turn it off when this process shares its cores with other work or must idle quietly on battery; the change holds at once, in every build, for the whole process. `CLIKA_RT_DISABLE_SPINNING=1` in the environment is the same switch set before the process starts.

<div class="api-declared">

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

</div>

### spinning\_allowed() {#spinning_allowed}

<div class="api-signature">

`bool` **`spinning_allowed`**()

</div>

Whether idle threads spin before they sleep (see [`set_spinning_allowed`](./index.md#set_spinning_allowed)).

<div class="api-declared">

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

</div>

### num\_physical\_cores() {#num_physical_cores}

<div class="api-signature">

`unsigned` **`num_physical_cores`**()

</div>

Number of physical CPU cores on the host.

<div class="api-declared">

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

</div>

### num\_logical\_cores() {#num_logical_cores}

<div class="api-signature">

`unsigned` **`num_logical_cores`**()

</div>

Number of logical CPU cores on the host (physical cores × SMT siblings).

<div class="api-declared">

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

</div>
