Multithreaded Programming Guide


The Multithreaded Programming Guide describes the multithreaded programming interfaces for POSIX® threads and Solaris threads in the SolarisTM Operating System (Solaris OS). This guide shows application programmers how to create new multithreaded programs and how to add multithreading to existing programs.

Although this guide covers both the POSIX and Solaris threads interfaces, most topics assume a POSIX threads interest. Information applying to only Solaris threads is covered in Chapter 6, Programming With Solaris Threads. The two sets of interfaces share a common implementation and are fully compatible with one another. Calls to POSIX threads interfaces can be freely intermixed with calls to Solaris threads interfaces.

POSIX threads information can be found in the Single UNIX Specification Version 3 at

Note –

This Solaris release supports systems that use the SPARC® and x86 families of processor architectures: UltraSPARC®, SPARC64, AMD64, Pentium, and Xeon EM64T. The supported systems appear in the Solaris 10 Hardware Compatibility List at This document cites any implementation differences between the platform types.

In this document the term “x86” refers to 64-bit and 32-bit systems manufactured using processors compatible with the AMD64 or Intel Xeon/Pentium product families. For supported systems, see the Solaris 10 Hardware Compatibility List.

Who Should Use This Book

This guide is for application developers who want to create new multithreaded programs or add multithreading to existing programs.

Developers that use this book should be familiar with and be able to use the following technologies:

How This Guide Is Organized

Chapter 1, Covering Multithreading Basics gives a structural overview of threads implementation in this release.

Chapter 2, Basic Threads Programming discusses the general POSIX threads routines, emphasizing creating a thread with default attributes.

Chapter 3, Thread Attributes covers creating a thread with nondefault attributes.

Chapter 4, Programming with Synchronization Objects covers the threads synchronization routines.

Chapter 5, Programming With the Solaris Software discusses changes to the operating environment to support multithreading.

Chapter 6, Programming With Solaris Threads covers the Solaris threads (as opposed to POSIX threads) interfaces.

Chapter 7, Safe and Unsafe Interfaces covers multithreading safety issues.

Chapter 8, Compiling and Debugging covers the basics of compiling and debugging multithreaded applications.

Chapter 9, Programming Guidelines discusses issues that affect programmers writing multithreaded applications.

Appendix A, Extended Example: A Thread Pool Implementation shows how to implement a pool of worker threads.

Related Third-Party Web Site References

Third-party URLs are referenced in this document and provide additional, related information.

Note –

Sun is not responsible for the availability of third-party web sites mentioned in this document. Sun does not endorse and is not responsible or liable for any content, advertising, products, or other materials that are available on or through such sites or resources. Sun will not be responsible or liable for any actual or alleged damage or loss caused or alleged to be caused by or in connection with use of or reliance on any such content, goods, or services that are available on or through such sites or resources.

Documentation, Support, and Training

The Sun web site provides information about the following additional resources:

Related Books

Multithreading requires a different way of thinking about function interactions. The following books are recommended reading.

Typographic Conventions

The following table describes the typographic changes used in this book.

Table P–1 Typographic Conventions

Typeface or Symbol 




The names of commands, files, and directories; on-screen computer output 

Edit your .login file.

Use ls -a to list all files.

machine_name% you have mail.


What you type, contrasted with on-screen computer output 

machine_name% su Password:


Command-line placeholder: replace with a real name or value 

To delete a file, type rm filename.


Book titles, new words, or terms, or words to be emphasized. 

Read Chapter 6 in User's Guide.

These are called class options.

You must be root to do this.

Shell Prompts in Command Examples

The following table shows the default system prompt and superuser prompt for the C shell, Bourne shell, and Korn shell.

Table P–2 Shell Prompts



C shell prompt 


C shell superuser prompt 


Bourne shell and Korn shell prompt 


Bourne shell and Korn shell superuser prompt