Q_POOL_CREATE(3)
๐ Q_POOL_CREATE ๐
okay bestie, we're in the Librecast Programmer's Manual today, and the vibe is: thread pools. two functions, one job โ q_pool_create and q_pool_destroy, aka initialize and destroy thread pools. that's the whole name section, and honestly? it ate. โจ
๐ LIBRARY
it's the Librecast library, fr fr โ that's liblibrecast, and you link it with -llibrecast. ๐ซถ
โจ SYNOPSIS โจ
first, the include, no cap:
#include <librecast/q.h>
then the two icons themselves:
int q_pool_create(pthread_t tid[], int nthreads, void *(*f)(void *), void *restrict arg);
int q_pool_destroy(pthread_t tid[], int nthreads);
and when you build it, you compile and link with -llibrecast. that's it, that's the whole ritual ๐
๐ง DESCRIPTION ๐ง
so. q_pool_create() spins up a thread pool of nthreads threads, and it uses f and arg as the start_routine and the argument for each thread. every single one. equal opportunity threads. ๐
and like โ the whole point of q_pool_create() is that it's designed to be used with q_job_seek(3), so you can start a thread pool of workers that process jobs from a smolq queue. it's giving worker bee energy ๐
then when you're done and you want those threads gone, you call q_pool_destroy(). that's the one that cancels and reaps the threads you made with q_pool_create(3). closure, bestie. it's important.
and a lil detail that matters:tidmust be an array ofpthread_tof sizenthreads. don't be out here passing whatever, okay? the size has to match. ๐ธ
๐ RETURN VALUE ๐
these functions return zero on success. iconic. we love a zero.
but on error? they return the number of threads that failed to start or stop, and errno gets set to indicate the error. so it's not just "oops" โ it's "oops, and here's how many oopses". ๐
now listen, this part is important: ifq_pool_create()successfully starts any threads, those are not cancelled if there's a failure starting a later thread. they just keep going. so you gotta callq_pool_destroy(3)to destroy the created threads when you're done โ and you passnthreadsminus the return value from the failed call toq_pool_create()to stop the running threads. do the math, bestie. ๐งฎ
๐ ERRORS ๐
q_pool_create() may fail with any of the errors for pthread_create(3). that's the whole list. go check pthread_create(3), iykyk.
๐ SEE ALSO ๐
the whole friend group, go say hi:
and that's the page, bestie!! ๐ฆ this one's from the LIBRECAST crew, dated 2023-07-23, and you can find it filed under Q_POOL_CREATE(3). go forth and pool your threads responsibly ๐โจ๐
๐ฆ where this page comes from
- debian trixie: liblibrecast-dev 0.9.1-1 ยท GPL-2.0-only OR GPL-3.0-only
- nixos 26.05: librecast 0.11.2
- nixpkgs unstable: librecast 0.11.2
- ubuntu noble: liblibrecast-dev 0.8.0-1.1build1 ยท GPL-2.0-only OR GPL-3.0-only
- ubuntu questing: liblibrecast-dev 0.9.1-1
- ubuntu resolute: liblibrecast-dev 0.11.2-2 ยท GPL-2.0-only OR GPL-3.0-only
- ubuntu stonking: liblibrecast-dev 0.11.2-2build1 ยท GPL-2.0-only OR GPL-3.0-only
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms