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 is zero.

The thread_pool_destroy() function calls the unblock handler provided in the pool attribute structure. The unblock handler is called at least once for every thread in the thread pool. Once the unblock handler is called, the thread calling thread_pool_destroy() blocks until the number of threads in the thread pool drops to zero. When there are no more threads in the thread pool, the handle pool is freed and thread_pool_destroy() returns.

Because thread_pool_destroy() can return even if the threads in the pool are still finishing their cleanup sequence, it is possible to call context_free() after thread_pool_destroy(), but without reference to the freed thread pool memory.

Note: A side effect of this behavior is that a thread that's created by the thread pool can't call thread_pool_destroy() because the thread pool count never drops to zero, and subsequently 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