img
. .
nor OS/2), more than one user can log in to the machine independently and run programs
simultaneously.
Thus, in Figure 2-3, process P1 can be run by user Kim while P2 and P3 are being run by user Dan,
and P4 by user Bil. There is also no particular restriction on the amount of memory that a process
can have. P2 might use twice as much memory as P1, for example. It is also true that no two
processes can see or change each other's memory unless they have set up a special shared memory
segment.
Figure 2-3. Processes on a Multitasking System
For all the user programs in all the operating systems mentioned so far, each has one stack, one
program counter, and one set of CPU registers per process. So each of these programs can do only
one thing at a time. They are single threaded.
What Is a Thread?
Just as multitasking operating systems can do more than one thing concurrently by running more
than a single process, a process can do the same by running more than a single thread. Each thread
is a different stream of control that can execute its instructions independently, allowing a
multithreaded process to perform numerous tasks concurrently. One thread can run the GUI while
a second thread does some I/O and a third performs calculations.
A thread is an abstract concept that comprises everything a computer does in executing a
traditional program. It is the program state that gets scheduled on a CPU; it is the "thing" that does
the work. If a process comprises data, code, kernel state, and a set of CPU registers, then a thread
is embodied in the contents of those registers--the program counter, the general registers, the
stack pointer, etc., and the stack. A thread, viewed at an instant of time, is the state of the
computation.
"Gee," you say, "That sounds like a process!" It should. They are conceptually related. But a
process is a heavyweight, kernel-level entity and includes such things as a virtual memory map,
file descriptors, user ID, etc., and each process has its own collection of these. The only way for
your program to access data in the process structure, to query or change its state, is via a system
call.
Search WWH :
Custom Search
Previous Page
Multithreaded Programming with JAVA - Topic Index
Next Page
Multithreaded Programming with JAVA - Bookmarks
Home