Open System Services Programmer's Guide

Programs With Multiple Independent Application Threads
Programs containing multiple threads can improve performance by providing concurrent execution.
An application thread is independent if it does not explicitly share application resources that exist
in the process environment, such as application file opens, SQL cursors, or modifiable application
data structures.
This type of application includes simple OSS servers that maintain the application state in a
database. Such a server simplifies server design because then application state does not need to
be maintained in the server and thus most servers can be context-free. In cases where context must
be maintained across multiple requests, the context is generally private to the client and should
not be shared.
“Threading Considerations (page 428) describes some considerations for developing an application
with multiple application threads.
Programs With Multiple Interdependent Application Threads
An application thread is interdependent if it shares application resources that exist in the process
environment, such as application file opens, SQL cursors, and modifiable application data structures.
Applications with multiple interdependent application threads must synchronize access to the shared
application resources.
This type of application includes OSS servers that maintain application state in the server to improve
performance or that share resources, such as file opens, to reduce resource consumption. This type
of application also includes client programs that use parallelism.
Programs with multiple interdependent application threads can be synchronized by using mutexes
to reserve access to a shared resource and by using condition variables to wait for a shared
resource to be in a certain state.
Poor performance can result if inappropriate synchronization techniques are used. Synchronizing
at too coarse a level can overly restrict concurrency and cause a server to serialize processing,
dramatically increasing the application’s service time. Synchronizing at too fine a level can result
in an increase in the processor cycles spent on initializing, obtaining, and releasing mutexes and
dispatching threads.
Threaded Application Examples
The following example application creates a threaded time-of-day server socket that listens for
connections and upon connection, creates a thread to handle the connection.
432 Using the POSIX User Thread (PUT) Model Library