Академический Документы
Профессиональный Документы
Культура Документы
Systems:
Internals
and Design
Principles Chapter 5-1
Threads
Eighth Edition
By William Stallings
Processes and Threads
of a thread is not
recognized, is referred
to as a single-threaded
approach multiple processes
one thread per process
multiple processes
multiple threads per process
approaches
A Java run-time
environment is an multiple processes multiple processes
example of a system one thread per process multiple threads per process
RPC RPC
Request Request
Process 1
Server Server
RPC Server
Request
Thread A (Process 1)
Thread B (Process 1)
RPC
Request Server
Thread A (Process 1)
Thread B (Process 1)
User Level
Thread (ULT)
Kernel level
Thread (KLT)
User-Level Threads (ULTs)
All thread
management is Threads User
Library Space
done by the
application Kernel
Space
Process B Process B
Ready Running Ready Running
Blocked Blocked
(c) (d)
Thread 1 Thread 2 Thread 1 Thread 2
Ready Running Ready Running Ready Running Ready Running
Process B Process B
Ready Running Ready Running
Blocked Blocked
Colored state
is current state
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
er User done by Threads
the kernel
User
ace Space Library Space
no thread management
nel Kernel is done by the Kernel
ace Space Space
application
Windows is an
example of this
P P
approach P
Kernel-Level
Operation User-Level Threads Threads Processes
Null Fork 34 948 11,300
Signal Wait 37 441 1,840
Table 4.1
Thread and Process Operation Latencies (s)
Combined Approaches
Table 4.2
Relationship between Threads and Processes
6
5%
relative speed
10%
4
0%
8
2
2%
relative speedup
6
5%
0
1 2 3 4 5 6 7 8
10% number of processors
4 (a) Speedup with 0%, 2%, 5%, and 10% sequential portions
2 2.5
2.0 5%
0 10%
1 2 3 4 5 6 7 8 15%
20%
relative speedup
number of processors 1.5
(a) Speedup with 0%, 2%, 5%, and 10% sequential portions
1.0
2.5 0.5
5% 0
2.0 1 2 3 4 5 6 7 8
10%
15% number of processors
20%
relative speedup
1.0
Figure 4.7 Performance Effect of Multiple Cores
64
Oracle DSS 4-way join
TMC data mining
DB2 DSS scan & aggs
Oracle ad hoc insurance OLTP
48
g
l in
ca
ts
ec
scaling
rf
pe
32
16
0
0 16 32 48 64
number of CPUs
Scene List
Particles
Character
Bone Setup
Draw
Etc.
Available
Handle Table objects
Handle1 Thread x
Handle2 File y
Handle3 Section z
Processes Threads
an entity a dispatchable
corresponding unit of work
to a user job or that executes
application that sequentially and
owns resources is interruptible
Process ID A unique value that identifies the process to the operating system.
Security descriptor Describes who created an object, who can gain access to or use the
object, and who is denied access to the object.
Base priority A baseline execution priority for the process's threads. Table 4.3
Default processor affinity The default set of processors on which the process's threads can
run. Windows
Quota limits The maximum amount of paged and nonpaged system memory,
paging file space, and processor time a user's processes can use. Process
Execution time The total amount of time all threads in the process have executed.
Object
I/O counters Variables that record the number and type of I/O operations that
the process's threads have performed.
Attributes
VM operation counters Variables that record the number and types of virtual memory
operations that the process's threads have performed.
Thread context The set of register values and other volatile data that defines the
execution state of a thread.
Dynamic priority The thread's execution priority at any given moment. Table 4.4
Base priority The lower limit of the thread's dynamic priority.
Thread processor affinity The set of processors on which the thread can run, which is a Windows
subset or all of the processor affinity of the thread's process.
Thread execution time The cumulative amount of time a thread has executed in user mode Thread
and in kernel mode.
Alert status A flag that indicates whether a waiting thread may execute an
asynchronous procedure call. Object
Suspension count The number of times the thread's execution has been suspended
without being resumed. Attributes
Impersonation token A temporary access token allowing a thread to perform operations
on behalf of another process (used by subsystems).
Achieves concurrency
without the overhead of
using multiple processes
Preempted
Ready Running
Transition Unblock
Waiting Terminated
Resource Not Available
Not Runnable
user user
thread thread
Lightweight Lightweight
process (LWP) process (LWP)
syscall() syscall()
Kernel Kernel
thread thread
System calls
Kernel
Hardware
LWP 2 LWP 1
LWP ID LWP ID
Priority Priority
Signal Mask Signal Mask
Registers Registers
STACK STACK
A signal mask
thread_create() intr()
swtch()
syscall()
RUN ONPROC SLEEP
preempt()
wakeup()
signal signal
Running
State
termination
creation
Ready scheduling Executing Zombie
event
signal
or
event
Uninterruptible
Interruptible
Broadcast Content
Receiver Provider
Application
Activity Service
Dedicated
Virtual Machine
onCreate()
Entire
Lifetime
onStart() onRestart()
User navigates
to the activity
Visible
Lifetime
onResume()
App process
killed Foreground
Lifetime User returns
to the activity
Resumed
Apps with higher
priority need memory
onPause()
Paused
User navigates
to the activity
onStop()
Stopped
onDestroy()
Activity
shut down