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.

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

}<br />

}<br />

fprintf (stderr, "Table empty, message from rcvid %d ignored, "<br />

"client blocked\n", rcvid);<br />

break;<br />

tp1.c<br />

For more information about this program, see “Controlling the number of threads” in<br />

the Processes and Threads chapter.<br />

/*<br />

* tp1.c<br />

*<br />

* Thread Pool Example (1)<br />

*<br />

* 1999 06 26 R. Krten<br />

*/<br />

#include <br />

#include <br />

#include <br />

#include <br />

#include <br />

char *progname = "tp1";<br />

void<br />

tag (char *name)<br />

{<br />

time_t t;<br />

char buffer [BUFSIZ];<br />

time (&t);<br />

strftime (buffer, BUFSIZ, "%T ", localtime (&t));<br />

printf ("%s %3d %-20.20s: ", buffer, pthread_self (), name);<br />

}<br />

THREAD_POOL_PARAM_T *<br />

blockfunc (THREAD_POOL_PARAM_T *ctp)<br />

{<br />

tag ("blockfunc"); printf ("ctp %p\n", ctp);<br />

tag ("blockfunc"); printf ("sleep (%d);\n", 15 * pthread_self ());<br />

sleep (pthread_self () * 15);<br />

tag ("blockfunc"); printf ("done sleep\n");<br />

tag ("blockfunc"); printf ("returning 0x%08X\n", 0x10000000 + pthread_self ());<br />

return ((void *) (0x10000000 + pthread_self ())); // passed to handlerfunc<br />

}<br />

THREAD_POOL_PARAM_T *<br />

contextalloc (THREAD_POOL_HANDLE_T *handle)<br />

{<br />

tag ("contextalloc"); printf ("handle %p\n", handle);<br />

tag ("contextalloc"); printf ("returning 0x%08X\n", 0x20000000 + pthread_self ());<br />

return ((void *) (0x20000000 + pthread_self ())); // passed to blockfunc<br />

}<br />

void<br />

April 30, 2009 Appendix: C • Sample Programs 321

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

Saved successfully!

Ooh no, something went wrong!