A thread is a sequential flow of control through a program. Multi-threaded programming is, thus, a form of parallel programming where several threads of control are executing concurrently in the program. All threads execute in the same memory space, and can therefore work concurrently on shared data. Multi-threaded programming differs from using multiple processes in that all threads share the same memory space (and a few other system resources, such as file descriptors), instead of running in their own memory space as is the case with processes.
There's an important distinction to maintain among the terms multi-processing, parallel processing, and concurrent processing. Parallel processing is true super-computer stuff, where multiple CPUs share the load of a single process by breaking it down and executing its code at the same time. Multi-processing allows for concurrent, not simultaneous, processing. In this case, different processes can be assigned for execution to different CPUs. This can result in overall reductions in the cost of scheduling processes. Whereas parallel processing starts with each CPU or CPU group having its own system bus to work with, in multi-processing there's a common system bus (i.e., bottleneck). So the idea of MP is you can get much of what parallel processing offers, but for far less cost. These are hardware-based strategies. Multi-threading, by contrast, is software-based. Using threads, it's possible to utilize CPU resources more efficiently. If one part of a program must wait on the results of a system interrupt, for example, another part of the program, say a calculation, could still run, rather than block on the pending interrupt. Multi-threaded programs therefore take advantage of time the CPU might otherwise simply be idling. Strictly speaking, a well-designed multi-threaded program will use resources more efficiently, the end result being that the overall time required for execution is less. ----------------- Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide [This message has been edited by Michael Ernest (edited December 29, 2000).]
Make visible what, without you, might perhaps never have been seen. - Robert Bresson
Hello, Could you explain, as much as possible, exactly how much of a resource saving threads can contribute to? It seems to me that even if threads are running in the same memory space, as one thread yields to another, some unique details about that thread will have to be saved. What, usually, are these details? In contrast what additional parameters are there for processes?