---
name: "q_pool_destroy"
section: "3"
platform: "linux"
package: "liblibrecast-dev"
version: "0.9.1-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/q_pool_create"
---

# q\_pool\_destroy(3)

initialize and destroy thread pools

Part of [q\_pool\_create(3)](/q_pool_create/3.md).

## NAME

q\_pool\_create, q\_pool\_destroy - initialize and destroy thread pools

## LIBRARY

Librecast library (*liblibrecast*, *-llibrecast*)

## SYNOPSIS

```
#include <librecast/q.h>
```

**int q\_pool\_create(pthread\_t** *tid\[\]***, int** *nthreads***, void \*(\****f***)(void \*), void \*restrict** *arg***);** **int q\_pool\_destroy(pthread\_t** *tid\[\]***, int** *nthreads***);**

Compile and link with *-llibrecast*.

## DESCRIPTION

The **q\_pool\_create**() function creates a thread pool of *nthreads* threads, using *f* and *arg* as the start\_routine and argument for each thread.

**q\_pool\_create**() is designed for use with [**q\_job\_seek**(3)](/q_job_seek/3.md) to start a thread pool of workers to process jobs from a smolq queue.

The **q\_pool\_destroy**() function is called to cancel and reap the threads created with [**q\_pool\_create**(3)](/q_pool_create/3.md).

*tid* must be an array of pthread\_t of size *nthreads*.

## RETURN VALUE

These functions return zero on success. On error, the number of threads that failed to start or stop is returned and *errno* is set to indicate the error.

If **q\_pool\_create**() successfully starts any threads, these are not cancelled if there is a failure starting a later thread. Call [**q\_pool\_destroy**(3)](/q_pool_destroy/3.md) to destroy the created threads when done, passing *nthreads* minus the return value from the failed call to **q\_pool\_create**() to stop the running threads.

## ERRORS

**q\_pool\_create**() may fail with any of the errors for [**pthread\_create**(3)](/pthread_create/3.md).

## SEE ALSO

[**q\_job\_seek**(3)](/q_job_seek/3.md), [**q\_push**(3)](/q_push/3.md), [**q\_wait**(3)](/q_wait/3.md), [**sem\_init**(3)](/sem_init/3.md), [**sem\_destroy**(3)](/sem_destroy/3.md), [**pthread\_create**(3)](/pthread_create/3.md)
