Expand description
Threads an app starts, bound to the app for CPU and memory attribution (ADR-314, contract C1). Threads an app starts, charged to the app (ADR-314).
A built-in app runs inside the host process, so every thread it starts burns host CPU and allocates host memory that nothing attributes to it on its own: the host can only count such a thread as unattributed, landing its cost on “the node”. The host therefore exports two hooks that register the calling thread with the app for the thread’s whole life (ADR-314 §4):
int node_host_thread_bind_v1(const void *host_data); /* 0 = bound */
void node_host_thread_unbind_v1(const void *host_data);spawn and Builder resolve both symbols once with
dlsym(RTLD_DEFAULT, …) and cache them: a host that predates ADR-314 does
not export them, and then the helpers still run your closure and bind
nothing. The app does not have to know which host it was loaded into.
Start every thread through spawn or Builder — for a tokio runtime,
through the tokio-gated runtime::Builder — or its CPU and its jemalloc
allocations stay outside the app’s figures and count as the node’s
unattributed threads (ADR-314 §3).
Structs§
- Builder
- Thread factory mirroring
std::thread::Builder, with app binding (ADR-314).
Functions§
- spawn
- Spawn an OS thread that is bound to this app (ADR-314).