C Collections

cthreadpool · Section 3

cthrpool_try_submit_future

cthrpool_try_submit_future - submit a future task without blocking

C Collections (libccollections, -lccollections)

#include <ccollections/cthreadpool.h>
 
ccol_retval cthrpool_try_submit_future(cthrpool pool,
                                         void *(*fn)(void *),
                                         void *arg,
                                         cthrpool_future **out);

Allocates a future and submits it to the pool, and never blocks: When
a bounded queue is at capacity the function returns
ccol_container_full at once and sets *out to NULL. With an unbounded
queue it behaves exactly like cthrpool_submit_future.
 
On success *out is set to a new cthrpool_future handle with a reference
count of 2: The caller holds one reference, and the queued task holds
the other. The caller must call cthrpool_future_free exactly once when
it is done.

pool  Thread pool handle
fn    Task function returning void* (must not be NULL)
arg   The library gives it to fn (may be NULL)
out   Receives the future handle on success. The function sets it to
      NULL on a failure (must not be NULL)

ccol_success           - task enqueued; *out set to the future handle.
ccol_invalid_args      - pool is CTHRPOOL_NULL or a stale/already-destroyed handle, or fn or out is NULL.
ccol_not_enough_memory - future or task allocation failed.
ccol_not_permitted     - pool is shutting down.
ccol_container_full    - bounded queue is at capacity.

cthrpool_submit_future(3), cthrpool_timed_submit_future(3), cthrpool_future_get(3), cthrpool_future_free(3)