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


1.  Covering Multithreading Basics

2.  Basic Threads Programming

Lifecycle of a Thread

The Pthreads Library

Creating a Default Thread

pthread_create Syntax

pthread_create Return Values

Waiting for Thread Termination

pthread_join Syntax

pthread_join Return Values

Simple Threads Example

Detaching a Thread

pthread_detach Syntax

pthread_detach Return Values

Creating a Key for Thread-Specific Data

pthread_key_create Syntax

pthread_key_create Return Values

Deleting the Thread-Specific Data Key

pthread_key_delete Syntax

pthread_key_delete Return Values

Setting Thread-Specific Data

pthread_setspecific Syntax

pthread_setspecific Return Values

Getting Thread-Specific Data

pthread_getspecific Syntax

pthread_getspecific Return Values

Global and Private Thread-Specific Data Example

Getting the Thread Identifier

pthread_self Syntax

pthread_self Return Values

Comparing Thread IDs

pthread_equal Syntax

pthread_equal Return Values

Calling an Initialization Routine for a Thread

pthread_once Syntax

pthread_once Return Values

Yielding Thread Execution

sched_yield Syntax

sched_yield Return Values

Setting the Thread Policy and Scheduling Parameters

pthread_setschedparam Syntax

pthread_setschedparam Return Values

Getting the Thread Policy and Scheduling Parameters

pthread_getschedparam Syntax

pthread_getschedparam Return Values

Setting the Thread Priority

pthread_setschedprio Syntax

pthread_setschedprio Return Values

Sending a Signal to a Thread

pthread_kill Syntax

pthread_kill Return Values

Accessing the Signal Mask of the Calling Thread

pthread_sigmask Syntax

pthread_sigmask Return Values

Forking Safely

pthread_atfork Syntax

pthread_atfork Return Values

Terminating a Thread

pthread_exit Syntax

pthread_exit Return Values

Finishing Up

Cancel a Thread

Cancellation Points

Placing Cancellation Points

Cancelling a Thread

pthread_cancel Syntax

pthread_cancel Return Values

Enabling or Disabling Cancellation

pthread_setcancelstate Syntax

pthread_setcancelstate Return Values

Setting Cancellation Type

pthread_setcanceltype Syntax

pthread_setcanceltype Return Values

Creating a Cancellation Point

pthread_testcancel Syntax

pthread_testcancel Return Values

Pushing a Handler Onto the Stack

pthread_cleanup_push Syntax

pthread_cleanup_push Return Values

Pulling a Handler Off the Stack

pthread_cleanup_pop Syntax

pthread_cleanup_pop Return Values

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


Lifecycle of a Thread

When a thread is created, a new thread of control is added to the current process. Every process has at least one thread of control, in the program's main() routine. Each thread in the process runs simultaneously, and has access to the calling process's global data. In addition each thread has its own private attributes and call stack.

To create a new thread, a running thread calls the pthread_create() function, and passes a pointer to a function for the new thread to run. One argument for the new thread's function can also be passed, along with thread attributes. The execution of a thread begins with the successful return from the pthread_create() function. The thread ends when the function that was called with the thread completes normally.

A thread can also be terminated if the thread calls a pthread_exit() routine, or if any other thread calls pthread_cancel() to explicitly terminate that thread. A thread can also be terminated by the exit of the process that called the thread.