Threads Chapter4
Threads Chapter4
Systems:
Internals
and Design
Principles Chapter 4
Threads
Seventh Edition
By William Stallings
Operating Systems:
Internals and Design Principles
User Level
Thread (ULT)
Kernel level
Thread (KLT)
4.6a→4.6b
4.6a→4.6c
4.6a→4.6d
Figure 4.6 Examples of the Relationships between User-Level Thread States and Process States
ULTs
can run
Scheduling can be
on any
application specific
OS
Writing an application
as multiple processes
rather than multiple
threads
Kernel-Level Threads (KLTs)
Thread management is
done by the kernel
(could call them KMT)
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
Multicore Programming
Multicore or multiprocessor systems putting pressure on
programmers, challenges include:
Dividing activities
Balance
Data splitting
Data dependency
Testing and debugging
One-to-One
Many-to-Many
Many-to-One
Many user-level threads mapped to single
kernel thread
Examples:
Solaris Green Threads
GNU Portable Threads
One-to-One
Each user-level thread maps to kernel thread
Examples
Windows
Linux
Solaris 9 and later
Many-to-Many Model
Allows many user level threads
to be mapped to many kernel
threads
Implicit Threading
Growing in popularity as numbers of threads increase,
program correctness more difficult with explicit threads
Advantages:
Usually slightly faster to service a request with
an existing thread than create a new thread
Allows the number of threads in the
application(s) to be bound to the size of the
pool
Separating task to be performed from
mechanics of creating task allows different
strategies for running task
i.e.Tasks could be scheduled to run periodically
Windows API supports thread pools:
Threading Issues
Signal handling
Synchronous and asynchronous
Thread cancellation of target thread
Asynchronous or deferred
Thread-local storage
Scheduler Activations
Semantics of fork() and
exec()
Does fork()duplicate only the calling thread or all
threads?
Some UNIXes have two versions of
fork
exec() usually works as normal – replace the running
process including all threads
Signal Handling
n Signals are used in UNIX systems to notify a process that a particular
event has occurred.