Start a thread pool
#include <sys/dispatch.h> int thread_pool_start( void *pool );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The thread_pool_start() function starts the thread pool pool. The function may or may not return, depending on the flags that you passed to thread_pool_create().
#include <sys/dispatch.h> #include <stdio.h> #include <stdlib.h> int main( int argc, char **argv ) { thread_pool_attr_t pool_attr; thread_pool_t *tpp; dispatch_t *dpp; resmgr_attr_t attr; resmgr_context_t *ctp; if( (dpp = dispatch_create()) == NULL ) { fprintf( stderr, "%s: Unable to allocate \ dispatch context.\n", argv[0] ); return EXIT_FAILURE; } memset( &pool_attr, 0, sizeof (pool_attr) ); pool_attr.handle = dpp; pool_attr.context_alloc = dispatch_context_alloc; pool_attr.block_func = dispatch_block; pool_attr.unblock_func = dispatch_unblock; pool_attr.handler_func = dispatch_handler; pool_attr.context_free = dispatch_context_free; pool_attr.lo_water = 2; pool_attr.hi_water = 4; pool_attr.increment = 1; pool_attr.maximum = 50; if( (tpp = thread_pool_create( &pool_attr, POOL_FLAG_EXIT_SELF )) == NULL ) { fprintf( stderr, "%s: Unable to initialize \ thread pool.\n", argv[0] ); return EXIT_FAILURE; } … /* Never returns */ thread_pool_start( 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_create(), thread_pool_destroy()
Processes and Threads chapter of Getting Started with QNX Neutrino