cthreadpool · Section 3
cthrpool_future_create_detached
NAME
cthrpool_future_create_detached - create a standalone future with no pool or queued task
LIBRARY
C Collections (libccollections, -lccollections)
SYNOPSIS
#include <ccollections/cthreadpool.h> cthrpool_future *cthrpool_future_create_detached(char **err_str);
DESCRIPTION
Allocates a future that no cthread_pool task queue is behind. A producer outside the pool, such as an event-driven engine that is not itself a cthrpool worker, must call cthrpool_future_fulfill exactly once to deliver the result. On success the future has a reference count of 2, the same convention as with cthrpool_submit_future: The caller holds one reference, which cthrpool_future_free releases, and the producer holds the other one, which cthrpool_future_fulfill releases. Each cthrpool_future_get call that runs on the future adds one more for its duration. The struct is freed once every reference is gone, in whatever order they go. cthrpool_future_free can come before cthrpool_future_fulfill, and either call can come while other threads still wait in cthrpool_future_get, exactly as with a future that a pool is behind. The function always uses the standard malloc and free and never a custom allocator, the same as the futures of cthrpool_submit_future.
PARAMETERS
err_str Optional pointer to receive an error string on failure
(pass NULL to ignore)
RETURN VALUE
Returns a new cthrpool_future handle (not yet done) on success. Returns NULL on allocation failure.
SEE ALSO
cthrpool_future_fulfill(3), cthrpool_future_get(3), cthrpool_future_done(3), cthrpool_future_free(3)