Lect 4
Lect 4
Threads CHAPTER 4
2
Processes and Threads
A process
Unit of Scheduling/Execution
Unit of Resource Ownership
= instruction trace
RPC RPC
Request Request
Process 1
Server Server
RPC Server
Request
Thread A (Process 1)
Thread B (Process 1)
RPC
Request Server
Ready
Running
Blocked
(a) (b)
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
(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
14
Kernel-Level Threads
Implemented as objects
A process can be created as a new process or as a copy of
an existing process
An executable process may contain one or more threads
A Windows process must contain at least one thread to execute
That thread may then create other threads
A thread is a dispatchable unit of work
Both process and thread objects have built-in synchronization
capabilities
19
Windows Process Object Attributes
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.
Default processor affinity The default set of processors on which the process's threads can
run.
Quota limits The maximum amount of paged and nonpaged system memory,
paging file space, and processor time a user's processes can use.
Execution time The total amount of time all threads in the process have executed.
I/O counters Variables that record the number and type of I/O operations that
the process's threads have performed.
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.
Thread processor affinity The set of processors on which the thread can run, which is a
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
and in kernel mode.
Alert status A flag that indicates whether a waiting thread may execute an
asynchronous procedure call.
Suspension count The number of times the thread's execution has been suspended
without being resumed.
Runnable
Pick to Standby
Run Switch
Preempted
Ready Running
Transition Unblock
Waiting Terminated
Resource Not Available
Not Runnable
Process
user user
thread thread
Lightweight Lightweight
process (LWP) process (LWP)
syscall() syscall()
Kernel Kernel
thread thread
System calls
Kernel
Hardware
IDLE PINNED
thread_create() intr()
swtch()
syscall()
RUN ONPROC SLEEP
preempt()
wakeup()
State
Scheduling information
Identifiers
Interprocess communication
And others
25
Linux Threads
Stopped
signal signal
Running
State
termination
creation
Ready scheduling Executing Zombie
event
signal
or
event
Uninterruptible
Interruptible