FLINT3.7.0-dev

flint_request_threads, flint_give_back_threads

Synopsis#include <flint/thread_support.h>
slong flint_request_threads(thread_pool_handle ** handles, slong thread_limit)source
void flint_give_back_threads(thread_pool_handle * handles, slong num_handles)source

flint_request_threads obtains workers from the global pool for a computation that may use thread_limit threads in total, counting the caller. It stores an array of handles in *handles and returns the number w of workers obtained: 0 if \mathit{thread\_limit} \le 1, and otherwise at most \min(\mathit{thread\_limit}, \texttt{flint\_get\_num\_threads()}) - 1. flint_give_back_threads returns the workers and frees the array.

These are wrappers of thread_pool_request and thread_pool_give_back for global_thread_pool. flint_request_threads may obtain fewer workers than allowed, or none, when other threads hold part of the pool. It may allocate the array even when it returns w = 0, so always call flint_give_back_threads(handles, w); it accepts a NULL array. The guide Using the thread pool directly shows how to wake, wait for and give back the workers.

Guides#

Cite this page

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