[Return to Bookshelf] [Contents] [Previous Section] [Next Section] [Index] [Help]


1.1 Advantages of Using DECthreads

Threads are used to improve the performance (throughput, computational speed, responsiveness-or some combination) of a program. Multiple threads are useful in a multiprocessor system where threads run concurrently on separate processors. Threads created using the DECthreads library are capable of utilizing multiprocessors if the operating system on that platform supports parallelism within a process. Multiple threads also improve program performance on single processor systems by permitting the overlap of input, output, or other slow operations with computational operations.

Threads are useful in driving slow devices such as disks, networks, terminals, and printers. A multithreaded program can perform other useful work while waiting for the device to produce its next event (such as the completion of a disk transfer or the receipt of a packet from the network).

It is also advantageous to use threads when constructing a user interface. Consider the typical arrangement of a window system. Each time the user invokes an action (by clicking on a mouse button for example), a separate thread can be used to implement the action. If the user invokes multiple actions, multiple threads perform the actions in parallel. (Note that the implementation of the window system can also use a thread to handle the interaction with the user, because the user is an example of a slow device.)

Threads are especially advantageous to use when building a distributed system. These systems frequently contain a shared network server, where the server services requests from multiple clients. Using multiple threads allows the server to handle clients' requests in parallel, instead of artificially serializing them (or creating one server process per client, at great expense).