MT Auto Mode

In the Auto mode, the RPC library creates and manages threads. The service
developer invokes a new interface call, rpc_control(),
to put the server into MT Auto mode before invoking the svc_run() call. In this mode, the programmer needs only to ensure that service
procedures are MT safe.

rpc_control() enables applications to set and modify
global RPC attributes. At present, this function supports only server-side
operations. The following table shows the rpc_control()
operations defined for Auto mode. See also the rpc_control(3NSL) man page
for additional information.

Table 7–1 rpc_control() Library Routines

Routine

Description

RPC_SVC_MTMODE_SET()

Set multithread mode

RPC_SVC_MTMODE_GET()

Get multithread mode

RPC_SVC_THRMAX_SET()

Set maximum number of
threads

RPC_SVC_THRMAX_GET()

Get maximum number of
threads

RPC_SVC_THRTOTAL_GET()

Total number
of threads currently active

RPC_SVC_THRCREATES_GET()

Cumulative
total number of threads created by the RPC library

RPC_SVC_THRERRORS_GET()

Number of thr_create() errors within RPC library

Note –

All of the get operations in Table 7–1,
except RPC_SVC_MTMODE_GET(), apply only to the Auto MT
mode. If used in MT User mode or the single-threaded default mode, the results
of the operations might be undefined.

By default, the maximum number of threads that the RPC server library
creates at any time is 16. If a server needs to process more than 16 client
requests concurrently, the maximum number of threads must be set to the desired
number. This parameter can be set at any time by the server. It enables the
service developer to put an upper bound on the thread resources consumed by
the server. Example 7–1 is an example RPC program written
in MT Auto mode. In this case, the maximum number of threads is set at 20.

MT performance is enhanced if the function svc_getargs()
is called by every procedure other than NULLPROCS, even
if there are no arguments (you can use xdr_void() in this
case). This is true for both the MT Auto and MT User modes. For more information
on this call, see the rpc_svc_calls(3NSL) man page.

Note –

You must link in the thread library when writing RPC multithreaded-safe
applications. The thread library must be the last named library on the link
line. Specify the -lthread option in the compile command.

The following example illustrates the server in MT Auto mode. To compile
this program, type cc time_svc.c -lnsl -lthread.