STREAMS/UX for the HP 9000 Reference Manual
117
How to Compile and Link STREAMS/UX Drivers, Modules, and Applications
Compiling and Linking TLI/XTI Applications and Threads
recommended that for loopback applications, the sending and receiving threads
be in separate processes which will avoid any deadlock situation.
NOTE: The libraries use two levels of internal locks and it is only during the small time
frame between obtaining and releasing the locks that a deadlock can occur.
• The libcma.a or libcma.sl library must be linked into the application before either
the libnsl_s.a or the libxti.a libraries are linked.
• The include file, pthread.h, must be the first include file defined within an
application to have all entry points properly mapped.
• Independent of the TLI/XTI libraries, if you cancel a thread and it was either
waiting on a mutex or a condition variable, it is best to consider either the mutex
or the condition variable as corrupted and either re-initialize or destroy and
recreate them.
Here are some basic tips on coding TLI/XTI multi-threaded applications.
• The pthreads library is a user space library. Threads execute using either the
default round-robin scheduling mechanism or a scheduling mechanism that the
application controls. The default order of execution is not predictable nor should
it be relied upon. For instance, if a thread spawns multiple threads, the new
threads will not be allowed to execute until either the initiating thread executes a
blocking call, executes a pthread_yield(), or its time slice expires. It is
recommended that a thread executing a pthread_create() issue a pthread_yield()
and possibly a pthread_join() to allow the other threads a chance to execute and
finish their tasks before continuing its processing.
For TLI/XTI, this technique is useful for a responder application which listens
for incoming connections and creates a new thread to complete the connection.
In this case, the responder could either yield to the new thread or could continue
to listen for incoming connect indications until there are no pending indications.
At this time it yields or executes a poll call that will block, which allows the
other threads to be scheduled for execution. This avoids the potential TLOOK
error condition should another indication arrive before the previous one is
processed and cleared.
Another example is if the responder detects a POLLHUP condition exists and
creates a thread to handle the disconnect, and then continues to execute. The
result could be poll() detecting this condition occurring multiple times when it
really only exists once. It is recommended that the thread be coded such that
either a pthread_yield() is immediately executed following the pthread_create()
or if the responder thread is handling multiple connections, it executes a
pthread_join() and waits for the disconnect thread’s completion.