cthreadpool · Section 3
cthrpool_shutdown_immediate
NAME
cthrpool_shutdown_immediate - immediate shutdown
LIBRARY
C Collections (libccollections, -lccollections)
SYNOPSIS
#include <ccollections/cthreadpool.h> void cthrpool_shutdown_immediate(cthrpool pool);
DESCRIPTION
Cancels every task in the queue, and then tells each worker thread to exit once it finishes the task it is running, if it has one. The call blocks until every worker thread has exited. A cancelled task that cthrpool_submit(3), cthrpool_try_submit(3) or cthrpool_timed_submit(3) queued with an on_complete gets on_complete(arg, false), and its fn never runs. Those calls run on the thread that calls this function, before it returns, with no lock of the pool held. From such an on_complete, cthrpool_wait(3) and both shutdown functions on the same pool are no-ops, and cthrpool_destroy(3) on the same pool is a fatal error; see cthrpool_submit(3). The future of a cancelled task is marked as done and as cancelled, and every thread blocked in cthrpool_future_get on a cancelled future is woken up and gets NULL. A second call, whether it comes after the first one or at the same time on another thread, does no shutdown work of its own, but it still blocks until the shutdown that is under way ends. So every caller gets the same guarantee: Once the call returns, every worker thread has exited.
PARAMETERS
pool Thread pool handle (CTHRPOOL_NULL or a stale/already-destroyed
handle is a no-op)
NOTES
A task that is already running when you make this call finishes as usual. Every submit function returns ccol_not_permitted after this call; cthrpool_submit_future returns NULL and stores ccol_not_permitted in its rv_out. If a cthrpool_shutdown_drain is already running, this call escalates the drain instead of simply joining it: It discards whatever is left in the queue at that moment, cancels the futures of those tasks and calls on_complete(arg, false) for each of them that has one, exactly as if this call had started the shutdown. A task that the drain has already started still finishes as usual. A call to cthrpool_shutdown_immediate on pool from inside a task running on one of pool's worker threads, or from the on_complete callback of that task, does nothing at all, for the reason cthrpool_shutdown_drain gives for the same case: A worker thread cannot join itself. The call neither discards the queue nor blocks.
SEE ALSO
cthrpool_shutdown_drain(3), cthrpool_future_cancelled(3), cthrpool_submit(3), cthrpool_destroy(3)