setThreads

fnvoid setThreads(size_t n) @trusted

Sets the process-wide ddn.df thread count for subsequent dispatches (ADR-2026-10-23-05).

The call outranks DDN_DF_MAX_THREADS (which stays the process-level default, read once as before); repeated calls are allowed, and a same-value call is a no-op. A size-changing call installs a new pool generation immediately and never blocks on running operations: each dispatch holds a use-counted reference to the pool it started with, in-flight operations complete on their pool with unchanged results, and the retired pool stops when its last user releases it.

Parameters

nthe thread count for subsequent dispatches

Throws

DataFrameException when n is below 1. Values above the

core count clamp to the core count, mirroring the environment variable's semantics.

Example:

// An embedding server tunes the library at startup and on request:
ddn.df.setThreads(4);
// ... later, a control endpoint halves the pool:
ddn.df.setThreads(2);
// In-flight operations finish on the old generation, bit-identically;
// every subsequent dispatch uses two threads.
assert(ddn.df.threads() == 2);

Note

when spawning your own worker threads that call into the

library, carry per-thread state on a class or struct field - on the current toolchains (verified live, LDC 1.43 and DMD 2.114) a delegate passed to core.thread.Thread that reads a foreach body variable sees the shared context, not a per-iteration copy.