26.02.2014 Views

Getting Started with QNX Neutrino - QNX Software Systems

Getting Started with QNX Neutrino - QNX Software Systems

Getting Started with QNX Neutrino - QNX Software Systems

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

More on synchronization<br />

© 2009, <strong>QNX</strong> <strong>Software</strong> <strong>Systems</strong> GmbH & Co. KG.<br />

thread_pool_start (void *pool);<br />

int<br />

thread_pool_limits (thread_pool_t *pool,<br />

int lowater,<br />

int hiwater,<br />

int maximum,<br />

int increment,<br />

unsigned flags);<br />

int<br />

thread_pool_control (thread_pool_t *pool,<br />

thread_pool_attr_t *attr,<br />

uint16_t lower,<br />

uint16_t upper,<br />

unsigned flags);<br />

As you can see from the functions provided, you first create a thread pool definition<br />

using thread_pool_create(), and then start the thread pool via thread_pool_start().<br />

When you’re done <strong>with</strong> the thread pool, you can use thread_pool_destroy() to clean<br />

up after yourself. Note that you might never call thread_pool_destroy(), as in the case<br />

where the program is a server that runs “forever.” The thread_pool_limits() function is<br />

used to specify thread pool behavior and adjust attributes of the thread pool, and the<br />

thread_pool_control() function is a convenience wrapper for the thread_pool_limits()<br />

function.<br />

So, the first function to look at is thread_pool_create(). It takes two parameters, attr<br />

and flags. The attr is an attributes structure that defines the operating characteristics of<br />

the thread pool (from ):<br />

typedef struct _thread_pool_attr {<br />

// thread pool functions and handle<br />

THREAD_POOL_HANDLE_T *handle;<br />

THREAD_POOL_PARAM_T<br />

*(*block_func)(THREAD_POOL_PARAM_T *ctp);<br />

void<br />

(*unblock_func)(THREAD_POOL_PARAM_T *ctp);<br />

int<br />

(*handler_func)(THREAD_POOL_PARAM_T *ctp);<br />

THREAD_POOL_PARAM_T<br />

*(*context_alloc)(THREAD_POOL_HANDLE_T *handle);<br />

void<br />

(*context_free)(THREAD_POOL_PARAM_T *ctp);<br />

// thread pool parameters<br />

pthread_attr_t<br />

*attr;<br />

unsigned short<br />

lo_water;<br />

unsigned short<br />

increment;<br />

unsigned short<br />

hi_water;<br />

unsigned short<br />

maximum;<br />

} thread_pool_attr_t;<br />

I’ve broken the thread_pool_attr_t type into two sections, one that contains the<br />

functions and handle for the threads in the thread pool, and another that contains the<br />

operating parameters for the thread pool.<br />

70 Chapter 1 • Processes and Threads April 30, 2009

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!