Beruflich Dokumente
Kultur Dokumente
Threads
Process concept
Process scheduling
Interprocess communication
Deadlocks
Threads
2.5-1
2.5-2
2.5-3
Code
TCB2
TCB3
Data
Stack
User Space
Kernel Space
PCB
Ceng 334 - Operating Systems
2.5-4
Chracteristics of Threads
Characteristics of Threads
The TCB (thread control block) consist of
program counter
register set
stack space
Thus the TCB is a reduced PCB
A traditional process is equal to a task with one
thread
All threads in a process share the state of that
process
Ceng 334 - Operating Systems
2.5-5
Characteristics of Threads
Characteristics of Threads (Cont.)
They reside in the exact same memory space (user
memory), see the same code and data
When one thread alters a process variable (say, the
working directory), all the others will see the
change when they next access it
If one thread opens a file to read it, all the other
threads can also read from it.
Ceng 334 - Operating Systems
2.5-6
Characteristics of Threads
Characteristics of Threads (Cont.)
Because no system calls are involved, threads are
fast
There are no kernel structures affected by the
existence of threads in a program, so no kernel
resources are consumed -- threads are cheap
The kernel doesn't even know that threads exist
2.5-7
Thredas of a Taks
Threads of a Task
Threads
Threads
Program
Counter
Code segment
Ceng 334 - Operating Systems
Task
Data
segment
2.5-8
Multiple Threads
Single vs. Multiple Threads of
Execution
Single Thread
Start
Multiple Threads
Start
Edit Document
Edit Document
Print Document
Print Document
End
Ceng 334 - Operating Systems
End
2.5-9
10
Threads
The Thread Model (1)
15
17
19
Hybrid Implementations
Scheduler Activations
Goal mimic functionality of kernel threads
gain performance of user space threads
Problem:
Fundamental reliance on kernel (lower layer)
calling procedures in user space (higher layer)
21
Pop-Up Threads
22
2.5-10
25
Parallelism
Parallellism
Different threads can run on different
processors simultaneously with no special
input from the user and no effort on the part
of the programmer
2.5-11
26
Througput
Throughput
When a traditional, single-threaded program
requests a service from the operating
system, it must wait for that service to
complete, often leaving the CPU idle
Multithreading provides progress even
though one or more threads wait for an
event as long as other threads are active
Ceng 334 - Operating Systems
2.5-12
27
Reponsiveness
Responsiveness
Blocking one part of a process need not block the
whole process. Single-threaded applications that
do something lengthy when a button is pressed
typically display a "please wait" cursor and freeze
while the operation is in progress
If such applications were multithreaded, long
operations could be done by independent threads,
allowing the application to remain active and
making the application more responsive to the
user
Ceng 334 - Operating Systems
2.5-13
28
Communication
Communications
An application that uses multiple processes to
accomplish its tasks can be replaced by an
application that uses multiple threads to
accomplish those same tasks
Processes-to-process communication through
traditional IPC (interprocess communications)
facilities (e.g., pipes or sockets)
The threaded application can use the inherently
shared memory of the process
Ceng 334 - Operating Systems
2.5-14
29