1. Covering Multithreading Basics
4. Programming with Synchronization Objects
5. Programming With the Solaris Software
6. Programming With Solaris Threads
Comparing APIs for Solaris Threads and POSIX Threads
Similar Synchronization Functions--Read-Write Locks
Initializing Read-Write Locks With Intraprocess Scope
Initializing Read-Write Locks With Interprocess Scope
Trying to Acquire a Write Lock
Destroying the Read-Write Lock State
Similar Solaris Threads Functions
Getting the Minimal Stack Size
Acquiring the Thread Identifier
Access the Signal Mask of the Calling Thread
Creating a Thread-Specific Data Key
Setting the Thread-Specific Data Value
Getting the Thread-Specific Data Value
Similar Synchronization Functions--Mutual Exclusion Locks
Mutexes With Intraprocess Scope
Mutexes With Interprocess Scope
Mutexes With Interprocess Scope-Robust
Similar Synchronization Functions: Condition Variables
Initialize a Condition Variable
Condition Variables With Intraprocess Scope
Condition Variables With Interprocess Scope
Destroying a Condition Variable
cond_reltimedwait Return Values
Similar Synchronization Functions: Semaphores
Semaphores With Intraprocess Scope
Semaphores With Interprocess Scope
sema_destroy(3C) Return Values
Synchronizing Across Process Boundaries
Example of Producer and Consumer Problem
Special Issues for fork() and Solaris Threads
This section describes unique Solaris threads functions: suspending thread execution and continuing a suspended thread.
thr_suspend(3C) immediately suspends the execution of the thread specified by target_thread. On successful return from thr_suspend(), the suspended thread is no longer executing.
Because thr_suspend()suspends the target thread with no regard to the locks that the thread might be holding, you must use thr_suspend() with extreme care. If the suspending thread calls a function that requires a lock held by the suspended target thread, deadlock will result.
#include <thread.h> int thr_suspend(thread_t tid);
After a thread is suspended, subsequent calls to thr_suspend() have no effect. Signals cannot awaken the suspended thread. The signals remain pending until the thread resumes execution.
In the following synopsis, pthread_t tid as defined in pthreads is the same as thread_t tid in Solaris threads. tid values can be used interchangeably either by assignment or through the use of casts.
thread_t tid; /* tid from thr_create() */ /* pthreads equivalent of Solaris tid from thread created */ /* with pthread_create() */ pthread_t ptid; int ret; ret = thr_suspend(tid); /* using pthreads ID variable with a cast */ ret = thr_suspend((thread_t) ptid);
thr_suspend() returns zero after completing successfully. Any other return value indicates that an error occurred. When the following condition occurs, thr_suspend() fails and returns the corresponding value.
ESRCH
Description: tid cannot be found in the current process.
thr_continue(3C) resumes the execution of a suspended thread. Once a suspended thread is continued, subsequent calls to thr_continue() have no effect.
#include <thread.h> int thr_continue(thread_t tid);
A suspended thread is not awakened by a signal. The signal remains pending until the execution of the thread is resumed by thr_continue() .
pthread_t tid as defined in pthreads is the same as thread_t tid in Solaris threads. tid values can be used interchangeably either by assignment or through the use of casts.
thread_t tid; /* tid from thr_create()*/ /* pthreads equivalent of Solaris tid from thread created */ /* with pthread_create()*/ pthread_t ptid; int ret; ret = thr_continue(tid); /* using pthreads ID variable with a cast */ ret = thr_continue((thread_t) ptid)
thr_continue() returns zero after completing successfully. Any other return value indicates that an error occurred. When the following condition occurs, thr_continue() fails and returns the corresponding value.
ESRCH
Description: tid cannot be found in the current process.