thread_pool_destroy()

Free the memory allocated to a thread pool

Synopsis:

#include <sys/iofunc.h>
#include <sys/dispatch.h>

int thread_pool_destroy( thread_pool_t * pool );

Arguments:

pool
A thread pool handle that was returned by thread_pool_create().

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The thread_pool_destroy() function frees the memory allocated to a thread pool that's identified by the handle pool. This is done only after the number of threads in the pool reaches zero.

This function calls the unblock handler provided in the pool_attr.unblock_func field in the pool attributes structure given to thread_pool_create(). The unblock handler is called at least once for every thread in the pool. When this happens, the thread calling thread_pool_destroy() blocks until every thread has indicated receipt of the unblock request. At this point, the handle is freed and the function returns.

Because thread_pool_destroy() can return even if the threads in the pool are still finishing their cleanup, it is possible that another thread can call the context-freeing handler provided in the pool_attr.context_free field after the thread_pool_destroy() call completes.

Note: A side effect of this behavior is that a thread that's a member of the pool can't call thread_pool_destroy() because the thread pool count can never drop to zero in this case and hence, the function never returns.

Returns:

0
Success.
-1
An error occurred.

Examples:

#include <sys/dispatch.h>
#include <stdio.h>

int main( int argc, char **argv ) {
   thread_pool_t        *tpp;

   …

   thread_pool_destroy ( tpp );
}

For examples using the dispatch interface, see dispatch_create(), message_attach(), resmgr_attach(), and thread_pool_create().

Classification:

QNX Neutrino

Safety:  
Cancellation point Yes
Interrupt handler No
Signal handler No
Thread Yes