Free the memory allocated to a thread pool


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

int thread_pool_destroy( thread_pool_t * pool );


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



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


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.

Note: Prior to QNX Neutrino 6.1.0, this function simply deallocated the thread pool handle and returned. Although this was acceptable for servers that never exited (and consequently never shut down their thread pools), it's unsuitable for closing down a thread pool.

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.


An error occurred.


#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().


QNX Neutrino

Cancellation point Yes
Interrupt handler No
Signal handler No
Thread Yes