img
. .
·
The ability to create well-structured programs
The following sections elaborate further on these benefits.
Parallelism
Computers with more than one processor offer the potential for enormous application speedups
(Figure 2-8). MT is an efficient way for application developers to exploit the parallelism of the
hardware. Different threads can run on different processors simultaneously with no special input
from the user and no effort on the part of the programmer.
Figure 2-8. Different Threads Running on Different Processors
A good example is a process that does matrix multiplication. A thread can be created for each
available processor, allowing the program to use the entire machine. The threads can then compute
distinct elements of the resulting matrix by performing the appropriate vector multiplication.
Throughput
When a traditional, single-threaded program requests a service from the operating system, it must
wait for that service to complete, often leaving the CPU idle. Even on a uniprocessor,
multithreading allows a process to overlap computation with one or more blocking system calls
(Figure 2-9). Threads provide this overlap even though each request is coded in the usual
synchronous style. The thread making the request must wait, but another thread in the process can
continue. Thus, a process can have numerous blocking requests outstanding, giving you the
beneficial effects of doing asynchronous I/O while still writing code in the simpler synchronous
fashion.
Figure 2-9. Two Threads Making Overlapping System Calls
Search WWH :
Custom Search
Previous Page
Multithreaded Programming with JAVA - Topic Index
Next Page
Multithreaded Programming with JAVA - Bookmarks
Home