In a multithread client program, a thread can be created to issue each RPC request. When multiple threads share the same client handle, only one thread at a time is able to make an RPC request. All other threads wait until the outstanding request is complete. On the other hand, when multiple threads make RPC requests using different client handles, the requests are carried out concurrently. Two Client Threads Using Different Client Handles (Real Time) illustrates a possible timing of a multithreaded client implementation consisting of two client threads using different client handles.
The following figure shows the client side implementation of a multithreaded rstat program. The client program creates a thread for each host. Each thread creates its own client handle and makes various RPC calls to the given host. Because the client threads are using different handles to make the RPC calls, they can carry out the RPC calls concurrently.
Figure 5 Two Client Threads Using Different Client Handles (Real Time)
Compile the program in the code example by typing cc rstat.c -lnsl -lthread.