JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
Multithreaded Programming Guide     Oracle Solaris 11.1 Information Library
search filter icon
search icon

Document Information

Preface

1.  Covering Multithreading Basics

2.  Basic Threads Programming

3.  Thread Attributes

4.  Programming with Synchronization Objects

5.  Programming With the Oracle Solaris Software

6.  Programming With Oracle Solaris Threads

7.  Safe and Unsafe Interfaces

8.  Compiling and Debugging

9.  Programming Guidelines

A.  Extended Example: A Thread Pool Implementation

What is a Thread Pool?

About the Thread Pool Example

Thread Pool Functions

thr_pool_create()

thr_pool_queue()

thr_pool_wait()

thr_pool_destroy()

Thread Pool Code Examples

thr_pool.h File

thr_pool.c File

What the Thread Pool Example Shows

Index

What the Thread Pool Example Shows

The example illustrates cancellation and unexpected thread termination, which is one of the trickier aspects of programming with threads. A worker thread might exit by calling pthread_exit() from within the task function passed to thr_pool_queue(), rather than just returning from the task function as expected. The thread pool recovers from this by catching the termination in a pthread_cleanup_push() function. The only harm done is that another worker thread must then be created. Worker threads that are actively processing tasks are cancelled in thr_pool_destroy(). A caller of thr_pool_wait() or thr_pool_destroy() may be cancelled by the application while it is waiting. This is also dealt with by using pthread_cleanup_push().

Although the example package is useful as it is, an application might require some features that are missing here, such as: