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.