Professional Documents
Culture Documents
Threads: What Is A Thread?
Threads: What Is A Thread?
Chapter 4
Threads
What is a Thread?
1
8/11/2021
What is a Thread?
Video Game
Process
video networking
interaction
2
8/11/2021
Benefits of Threads
• Takes less time to create a new thread than a process
• Less time to terminate a thread than a process
• Switching between two threads takes less time than
switching between processes
• Threads enhance efficiency in communication between
programs
Disadvantages???
3
8/11/2021
Threads
•an OS that supports threads, scheduling and
dispatching is done on a thread basis
•Most of the state information dealing with
execution is maintained in thread-level data
structures
•suspending a process involves suspending all
threads of the process
•termination of a process terminates all threads
within the process
4
8/11/2021
Multithreading on a Uniprocessor
10
5
8/11/2021
Thread Synchronization
•It is necessary to synchronize the activities of the
various threads
•all threads of a process share the same
address space and other resources
•any alteration of a resource by one thread
affects the other threads in the same
process
•For example, if two threads each try to
add an element to a doubly linked list at
the same time, one element may be lost
or the list may end up malformed.
11
Types of Threads
User Level
Thread (ULT)
Kernel level Thread
(KLT)
12
6
8/11/2021
13
14
7
8/11/2021
15
Advantages of KLTs
16
8
8/11/2021
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
17
Relationship Between
Threads and Processes
18
9
8/11/2021
19
Checkpoint
• Give four general examples of the use of threads in a single-user multiprocessing
system.
• What resources are typically shared by all of the threads of a process?
• List three advantages of ULTs over KLTs.
• List two disadvantages of ULTs compared to KLTs.
• It was pointed out that two advantages of using multiple threads within a process
are that (1) less work is involved in creating a new thread within an existing process
than in creating a new process, and (2) communication among threads within the
same process is simplified. Is it also the case that a mode switch between two threads
within the same process involves less work than a mode switch between two threads
in different processes?
• If a process exits and there are still threads of that process running, will they continue
to run?
20
10