FLINT3.7.0-dev

thread_pool_set_affinity, thread_pool_restore_affinity

Synopsis#include <flint/thread_pool.h>
int thread_pool_set_affinity(thread_pool_t T, int * cpus, slong length)source
int thread_pool_restore_affinity(thread_pool_t T)source

Pins the calling thread to processor cpus[0] and the threads of T to cpus[1], ..., cpus[length - 1] (threads beyond length - 1 are left alone), or restores the affinity that the calling thread had when T was created. Return 0 on success and an error code from pthread_setaffinity_np otherwise. Without CPU set support both functions do nothing and return 0.

The affinity restored by thread_pool_restore_affinity is that of the thread that called thread_pool_init, recorded at that point. It is applied both to the pool's threads and to the calling thread, so the function should be called from the thread that created the pool (for the global pool, the master thread, which creates it in flint_set_num_threads); any other thread receives the creator's affinity rather than its own original one.

Cite this page

The FLINT team, “thread_pool_set_affinity, thread_pool_restore_affinity (thread_pool.h),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/thread_pool/thread_pool_set_affinity.html (generated 2026-10-20).