cthreadpool · Section 3
cthrpool_declare_scoped
NAME
cthrpool_declare_scoped - declare a thread pool variable with automatic RAII destruction
LIBRARY
C Collections (libccollections, -lccollections)
SYNOPSIS
#include <ccollections/cthreadpool.h> cthrpool_declare_scoped(name);
DESCRIPTION
The same as cthrpool_declare(), plus a cleanup attribute, so the pool is destroyed when the variable leaves scope, exactly as cthrpool_destroy() would destroy it. You must still assign the variable before you use it. If it is still CTHRPOOL_NULL at the end of scope, the cleanup does nothing.
PARAMETERS
name Variable name to declare.
NOTES
It needs GCC or Clang, because it uses __attribute__((cleanup)). When the drain behavior matters, run a shutdown yourself before the end of scope: The shutdown that the destroy runs on its own drains the queue, and that drain can take any amount of time when the tasks are long.
EXAMPLES
{
cthrpool_declare_scoped(pool);
pool = cthrpool_create(4, 0, NULL);
cthrpool_submit(pool, my_fn, my_arg, NULL);
cthrpool_shutdown_drain(pool);
} /* pool is destroyed automatically here */
SEE ALSO
cthrpool_declare(3), cthrpool_construct_scoped(3), cthrpool_destroy(3)