cthreadpool · Section 3
cthrpool_future_free
NAME
cthrpool_future_free - release the caller's reference to a future
LIBRARY
C Collections (libccollections, -lccollections)
SYNOPSIS
#include <ccollections/cthreadpool.h> void cthrpool_future_free(cthrpool_future *f);
DESCRIPTION
Drops one reference to the future. When the reference count reaches zero, the future object is freed with the standard free(). Three kinds of holder release a reference: The caller, the worker, and every cthrpool_future_get call that is still in progress. For a detached future the producer holds one in place of the worker. The call never touches the void* result of the task function, which this module never allocates, copies or frees. cthrpool_future_get(3) says who owns the result. Call it exactly once for each successful cthrpool_submit_future, cthrpool_try_submit_future, cthrpool_timed_submit_future or cthrpool_future_create_detached call, whether cthrpool_future_get was called or not. If you call it and never call cthrpool_future_get, you get fire-and-forget behavior: The task still runs, and the future is freed automatically when the worker finishes, with the result thrown away. You can call it while other threads are inside cthrpool_future_get on the same future. Each of them holds its own reference, so the future is destroyed only after the last of them leaves. The call ends the caller's claim on f, as a thread giving up its last reference does. The caller must not use f again after the call, and must not hand f to a thread that is not inside cthrpool_future_get yet. A call to cthrpool_future_free with a NULL pointer does nothing.
PARAMETERS
f Future handle
SEE ALSO
cthrpool_submit_future(3), cthrpool_try_submit_future(3), cthrpool_timed_submit_future(3), cthrpool_future_get(3), cthrpool_future_create_detached(3), cthrpool_future_fulfill(3)