FTAM/9000 Programmer's Guide

Chapter 4 181
Using Support Functions
Responding to Asynchronous Calls
Waiting On FTAM and Non-FTAM Events
Use the em_hp_select() function when an application must
simultaneously wait for both an FTAM and a non-FTAM event to occur.
Without em_hp_select(), the application would need to implement a
“busy- wait” loop to poll for the FTAM and non-FTAM events. However,
this technique is very expensive in terms of CPU utilization, and
degrades system performance. This is unacceptable for most real-time or
highly interactive applications. Therefore, HP provides em_hp_select() as
an alternative method for waiting on both FTAM and non-FTAM events.
The em_hp_select() function suspends processing of the application until
an event occurs. While the application is suspended (i.e, blocked), it does
not contribute to the demand for CPU time. Therefore, the busy-wait
logic can be replaced with the following:
em_hp_select(...with indefinite timeout to block until event
occurs...)
handle_event))
If you need to wait only on FTAM events, use the em_wait() function. If
you need to wait only on non-FTAM events, use the HP–UX select()
system call. However, if you need to wait on both types of events
simultaneously, use the em_hp_select() function. Any combination of
em_wait(), select(), and em_hp_select() within the same program is valid;
all three functions are compatible with one another.
The following program example illustrates how to use em_hp_select() to
wait on FTAM and non-FTAM events simultaneously. The program
reads commands from stdin and starts the requested FTAM operation.
The operation is performed asynchronously so that new commands can
be read in before the previous operation completes. The operation results
are processed as they complete.
This program calls two functions to process the FTAM and non-FTAM
events. The logic for these functions is not shown in the example;
however, a brief description of each function follows.
read_and_process_command(). This function processes the
non-FTAM events by reading and parsing a command line string from
stdin. If the command is a “Quit” command, the function returns TRUE
to indicate termination. Otherwise, the appropriate FTAM operation is
initiated asynchronously. In this case, the function returns FALSE to
indicate more commands can be read from stdin.