Benefits of multiple threads

As an application designer, you can use multiple threads to allow different parts of a program to execute concurrently. For example, an interactive Client-Library application can use one thread to query a server and another thread to manage the user interface. Such an application seems more responsive to the user because the user-interface thread is able to respond to user actions while the query thread is waiting for results.As another example, consider an application that uses several connections to one or more servers. In this situation, each connection can be run within a dedicated thread. Then, while one thread is waiting for command results, the other threads can be processing received results or sending new commands. Such an approach may increase throughput because the application spends less idle time while waiting for results.Another reason to use multiple threads is that on a multiple-processor system, the system’s thread library may schedule an application’s threads to run on different processors. Threads provide one method of achieving concurrency in a Client-Library program. The other method is to use Client-Library’s asynchronous programming interface. Asynchronous programming allows limited concurrency. For more information on this alternative, see “Asynchronous programming”.