OSF DCE Application Development Guide--Core Components

OSF DCE Application Development Guide—Core Components
7.4.3 Other Synchronization Methods
There is another synchronization method that is not anonymous: the join primitive. This
allows a thread to wait for another specific thread to complete its execution. When the
second thread is finished, the first thread unblocks and continues its execution. Unlike
mutexes and condition variables, the join primitive is not associated with any particular
shared data.
7.5 One-Time Initialization Routines
You probably have one or more routines that must be executed before any thread
executes code in your application, but must be executed only once regardless of the
sequence in which threads start executing. For example, you may want to create mutexes
and condition variables (each of which must be created only once) in an initialization
routine. Multiple threads can call the pthread_once( ) routine, or the pthread_once()
routine can be called multiple times in the same thread, resulting in only one call to the
specified routine.
Use the pthread_once() routine to ensure that your application initialization routine is
executed only a single time; that is, by the first thread that tries to initialize the
application. This routine is the only way to guarantee that one-time initialization is
performed in a multithreaded environment on a given platform. The pthread_once()
routine is of particular use for runtime libraries, which are often called for the first time
after multiple threads are created.
Refer to the thr_intro(3thr) reference page for a list of the DCE Threads routines which,
when called, implicitly perform any necessary initialization of the threads package. Any
application that uses DCE Threads must call one of these routines before calling any
other threads routines.
7.6 Thread-Specific Data
The thread-specific data interfaces allow each thread to associate an arbitrary value with
a shared key value created by the program.
Thread-specific data is like a global variable in which each thread can keep its own
value, but is accessible to the thread anywhere in the program.
Use the following routines to create and access thread-specific data:
The pthread_keycreate( ) routine to create a unique key value
The pthread_setspecific( ) routine to associate data with a key
The pthread_getspecific( ) routine to obtain the data associated with a key
7 12 Tandem Computers Incorporated 124245