Free the memory allocated to a thread pool
#include <sys/iofunc.h> #include <sys/dispatch.h> int thread_pool_destroy( thread_pool_t * pool );
libc
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 all the threads of the thread pool have exited.
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.
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 will never drop to zero, and subsequently the function will never return. |
#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().
Safety: | |
---|---|
Cancellation point | Yes |
Interrupt handler | No |
Signal handler | No |
Thread | Yes |
thread_pool_control(), thread_pool_create(), thread_pool_limits(), thread_pool_start()
Processes and Threads chapter of Getting Started with QNX Neutrino