Information Technology Reference
In-Depth Information
active|the operating system may spread this program's threads across
multiple processors, allowing it to finish its work more quickly.
Example: Parallel processing. Suppose a program running on a 16-
processor machine needs to multiply two large matrices together. For
matrix multiply C = A B, result entry C (i;j) is computed by taking
the dot product of the ith row of A and the jth column of B: C i;j =
N1
k=0 A (i;k) B (k;j) . So, we can divide the work of computing C into 16
parts, and create one thread to compute each part, and then compute
those parts on different processors in parallel. For example, thread 0
running on one processor might compute the upper left square:
=
x
C
A
B
3. Coping with high latency I/O devices. If a program has multiple
threads, then when some are waiting for I/O to complete, others can be
running.
User-level programs typically access I/O devices such as keyboards, screens,
disks, and networks via system calls. If a system call blocks because it
needs to wait for the I/O device, then the calling thread goes from the
Runningstate to theWaitingstate, and the scheduler chooses another
thread to run.
Example: Overlapping I/O and processing. For example, if a pro-
cess running on a single-processor machine needs to encrypt 100 files,
it might create two threads, each of which iterates through 50 files, read-
ing one file, encrypting it, reading the next, and so on. Then, while one
thread is waiting for a file to be read from disk, the other one can be
using the processor to encrypt the file it read from disk.
Threads without kernel support
In the body of the text, we describe how a an operating system can provide system calls
so that a process can create multiple threads and have multiple schedulable PCBs in
the kernel.
It is also possible to implement threads as a library completely at user level, without
any operating system support.
The basic idea is simple. The threads library instantiates all of its data structures
within the process: TCBs, the ready list, the finished list, and the waiting lists all are
just data structures in the process's address space. Then, calls to the threads library
are just procedure calls (similar to how the same functions are implemented within a
multi-threaded kernel as described above.)
 
Search WWH ::




Custom Search