Professional Documents
Culture Documents
Chapter 4
Threads
Patricia Roy
Manatee Community College, Venice, FL
2008, Prentice Hall
Multithreading
To support multiple, concurrent paths of
execution within a single process
Multithreading
MS-DOS supports a single user process
and thread
Some variants of UNIX support multiple
user processes but only one thread per
process
Java run-time environment is a single
process with multiple threads
Windows, Solaris, and other modern
versions of Unix support multiple processes
and multiple threads per process
Processes
A virtual address space which holds the
process image
Protected access to processors, other
processes (for interprocess
communication), files, and I/O resources
Threads
Speed of execution
Asynchronous processing
For example, a thread to do backup for a
word processor
Benefits of Threads
Takes less time to create a new thread
than a process
Experiment shows that it is 10 times faster
Benefits of Threads
Since threads within the same process
share memory and files, they can
communicate with each other without
invoking the kernel
Threads
Suspending a process involves
suspending all threads of the process
since all threads share the same address
space
Termination of a process, terminates all
threads within the process
Thread States
States associated with a change in thread
state
Spawn
Spawn another thread
Block
Unblock
Finish
Deallocate register context and stacks
User-Level Threads
All thread management is done by the
application
The kernel is not aware of the existence of
threads
User-Level Threads
User-Level Threads
Kernel-Level Threads
Kernel-Level Threads
Kernel-Level Threads
user-level threads
kernel-level threads
null fork
34 usec
948 usec
11,300 usec
signal-wait
37 usec
441 usec
1,840 usec
Operation
Kernel-level threads
A blocking system call will not block all peer
threads
Expensive to manage and to do context switch
LWP Features
A Short Survey
On awareness of CSE Bits & Bytes