Professional Documents
Culture Documents
Chapter 4 Threads
Chapter 4 Threads
Chapter 4 Threads
Systems:
Internals
and
Design Chapter 4
Principles Threads
Seventh Edition
By William Stallings
Operating Systems:
Internals and Design Principles
suspending
Most a process
of the state involves
information suspending
dealing with all
threadsisofmaintained
execution the process
in thread-level data
termination ofstructures
a process terminates all threads
within the process
Thread Execution States
Kernel
User Level
levelThread
Thread(ULT)
(KLT)
User-Level Threads (ULTs)
All thread
management is
done by the
application
The kernel is not
aware of the
existence of threads
Relationships Between ULT
States and Process States
Figure 4.6 Examples of the Relationships between User-Level Thread States and Process States
Advantages of ULTs
Thread
switching does
not require
Disadvantages of ULTs
Ina typical OS many system calls are blocking
as a result, when a ULT executes a system call,
not only is that thread blocked, but all of the
threads within the process are blocked
In
a pure ULT strategy, a multithreaded
application cannot take advantage of
multiprocessing
s
y
s
t
Overcoming ULT
e
m
Disadvantages
c
W
r
i
t
i
a
n
g
a
n
l
a
p
p
l
i
l
c
a
t
i
o
n
a
s
i
u
l
t
i
p
l
n
e
p
r
o
t
c
e
s
s
e
o
s
r
a
t
h
e
r
t
h
a
a
n
m
u
l
t
i
p
l
e
t
h
r
e
a
n
o
d
s
n
Kernel-Level Threads (KLTs)
Threadmanagement is
done by the kernel
no thread
management is done
by the application
Windows is an
example of this
approach
Advantages of KLTs
The kernel can simultaneously schedule multiple
threads from the same process on multiple
processors
If one thread in a process is blocked, the kernel can
schedule another thread of the same process
Kernel routines can be multithreaded
Disadvantage of KLTs
The transfer of control from one thread to another
within the same process requires a mode switch to
the kernel
Combined Approaches
Thread creation is done in
the user space
Bulk of scheduling and
synchronization of threads
is by the application
Solaris is an example
Relationship Between
Threads and Processes
Multiprocess applications
characterized by the presence of many single-threaded processes
Java applications
Multiinstance applications
multiple instances of the application in parallel
Windows Processes
Processes and services provided by the Windows Kernel are relatively simple and
general purpose
• implemented as objects
• created as new process or a copy of an existing
• an executable process may contain one or more threads
• both processes and thread objects have built-in synchronization
capabilities
Relationship Between
Process and Resource
Processes Threads
•an entity •a dispatchable unit
corresponding to a of work that
user job or executes
application that owns sequentially and is
resources interruptible
Windows Process and
Thread Objects
Windows Process Object
Attributes
Threads within the same process can Threads in different processes can
exchange information through their exchange information through
common address space and have access shared memory that has been set
to the shared resources of the process up between the two processes
Thread States
Process
•includes the user’s address space, stack, and
process control block
Kernel-level threads
threads within a process that are maintained by the kernel
a mode switch is required to switch from one thread to another
multiple threads within the same process can execute in parallel on a multiprocessor
blocking of a thread does not block the entire process
Process/related to resource ownership
Thread/related to program execution