OSF DCE Application Development Guide--Introduction and Style Guide
Threads
scheduling policy (SCHED_OTHER) mitigates the effects of priority inversion by
giving low-priority threads a chance to execute (and thus release held locks) even
when higher-priority threads are eligible to run.
• You may be able to use the global locking call pthread_lock_global_np() when
calling into libraries not known to be thread safe.
• Use the atfork( ) routine to keep the state of mutexes consistent across calls to
fork( ). Note, however, that this routine is not considered portable. Try to create
threads rather than processes whenever possible.
• Call pthread_cond_wait( ) from within a predicate loop, as in the following
example:
while (test_condition)
pthread_cond_wait();
• Set thread attributes via a thread attributes object before thread creation. Changes
to a thread attribute object after a thread has been created will not affect the thread’s
attributes. A thread can straightforwardly change its own scheduling attributes by
calling pthread_set_scheduler( ) and pthread_set_prio(), but cannot reliably
change the attributes of another thread once it has been created.
See Sections 2.3.3 and 2.3.4 for specific guidelines relating to cancels and signals.
2.3 Threads Programming Topics
The subsections that follow contain discussions of the following aspects of multithreaded
DCE application development:
• Thread handles and their use
• Storage for thread specific data
• Canceling threads
• Signals
2.3.1 Thread Handles
The pthread package provides thread handles to identify threads; these are returned as
the thread argument to pthread_create( ). Applications supply thread handles as thread
identifiers to the routines pthread_join( ), pthread_detach( ), and pthread_cancel().
Thread handles should be treated as opaque data; they may be compared by calling
pthread_equal(), but any other operations on thread handles are likely to be nonportable
and are thus discouraged.
124246 Tandem Computers Incorporated 2−7










