0% found this document useful (0 votes)
4 views

CH 04 -OS8e

Uploaded by

hamza37727
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

CH 04 -OS8e

Uploaded by

hamza37727
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 58

Operating

Systems:
Internals
and
Design
Principles Chapter 4
Threads
Eighth Edition
By William Stallings
Processes and
Threads
Resource Scheduling/
Ownership Execution
Process includes Follows an execution
a virtual address path that may be
space to hold the interleaved with other
process image processes
 the OS performs a  a process has an
protection function to execution state (Running,
prevent unwanted Ready, etc.) and a
interference between dispatching priority and is
processes with scheduled and dispatched
respect to resources by the OS
Processes and
Threads
 Theunit of dispatching is referred to as a
thread or lightweight process
 Theunit of resource ownership is referred to
as a process or task
 Multithreading - The ability of an OS to
support multiple, concurrent paths of
execution within a single process
Single Threaded
Approaches
 A single thread of
execution per
process, in which
the concept of a
thread is not
recognized, is
referred to as a
single-threaded
approach
 MS-DOS is an
Multithreaded
Approaches
 The right half of
Figure 4.1 depicts
multithreaded
approaches
 A Java run-time
environment is an
example of a
system of one
process with
multiple threads
Processes
 The unit or resource allocation and a unit of
protection
 A virtual address space that holds the
process image
 Protected access to:
 processors
 other processes
 files
 I/O resources
One or More
Threads
in a Process
Benefits of Threads
Thread Use in a
Single-User System
 Foreground and background
work
 Asynchronous processing
 Speed of execution
 Modular program structure
Threads
 In an OS that supports threads,
scheduling and dispatching is done on a
thread basis

 suspending a process involves


suspending all threads of the
process
 termination of a process terminates all
threads within the
process
Thread Execution
States

The key states Thread


for a thread operations
are: associated with
a change in
thread state are:
 Running
 Ready  Spawn
 Blocked  Block
 Unblock
 Finish
Thread
Synchronization
 Itis necessary to synchronize the
activities of the various threads
 allthreads 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
Types of Threads
User-Level Threads
(ULTs)
 All
thread
management is
done by the
application
 Thekernel is not
aware of the
existence of
threads
Advantages of
ULTs
Disadvantages of
ULTs
 Ina typical OS many system calls are
blocking
 as a result, when a ULT executes a
system call, not only is that thread
blocked, but all of the threads within
the process are blocked
 In
a pure ULT strategy, a multithreaded
application cannot take advantage of
multiprocessing
Overcoming ULT
Disadvantages
Kernel-Level Threads
(KLTs)
 Thread
management is
done by the kernel
 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
 Kernel routines can be multithreaded
Disadvantage of KLTs
 The transfer of control from one thread
to another within the same process
requires a mode switch to the kernel

Table 4.1
Thread and Process Operation Latencies (s)
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
Table 4.2
Relationship between Threads and Processes
Applications That
Benefit
 Multithreaded native applications
 characterized by having a small number of
highly threaded processes
 Multiprocess applications
 characterized by the presence of many single-
threaded processes
 Java applications
 Multiinstance applications
 multiple instances of the application in parallel
Valve Game
Software
and
Thread
Management
 An application consists of  A thread pool is a
one or more processes collection of worker threads
that efficiently execute
 Each process provides the asynchronous callbacks on
resources needed to behalf of the application
execute a program
 A fiber is a unit of
 A thread is the entity execution that must be
within a process that can manually scheduled by the
be scheduled for execution application
 A job object allows groups  User-mode scheduling
of process to be managed (UMS) is a lightweight
as a unit mechanism that
applications can use to
schedule their own threads
Changes in Windows 8
 Changes the traditional Windows approach to managing
background tasks and application lifecycles
 Developers are now responsible for managing the state of their
individual applications
 In the new Metro interface Windows 8 takes over the process
lifecycle of an application
 a limited number of applications can run alongside the
main app in the Metro UI using the SnapView functionality
 only one Store application can run at one time

 Live Tiles give the appearance of applications constantly


running on the system
 in reality they receive push notifications and do not use
system resources to display the dynamic content offered
Metro Interface
 Foreground application in the Metro interface has access to
all of the processor, network, and disk resources available to
the user
 all other apps are suspended and have no access to these
resources
 When an app enters a suspended mode, an event should be
triggered to store the state of the user’s information
 this is the responsibility of the application developer
 Windows 8 may terminate a background app
 you need to save your app’s state when it’s suspended, in
case Windows terminates it so that you can restore its state
later
 when the app returns to the foreground another event is
triggered to obtain the user state from memory
Windows Processes
Process and Thread
Objects
Windows makes use of two types of
process-related objects:
Table 4.3

Windows

Process

Object

Attribute
s

(Table is
on page
175 in
textbook)
4.4

Window

Thread

Object

Attribut

es

(Table is on
page 175 in
textbook)
Multithreaded
Process
Solaris Process
makes use of four thread-related
concepts:
A Lightweight Process
(LWP) Data Structure
Includes:
 An LWP identifier
 The priority of this LWP
 A signal mask
 Saved values of user-level registers
 The kernel stack for this LWP
 Resource usage and profiling data
 Pointer to the corresponding kernel thread
 Pointer to the process structure
Interrupts as Threads
 Most operating systems contain two
fundamental forms of concurrent activity:
Solaris Solution

 Solaris employs a set of kernel threads


to handle interrupts
 an interrupt thread has its own identifier,
priority, context, and stack
 the kernel controls access to data
structures and synchronizes among
interrupt threads using mutual exclusion
primitives
 interrupt threads are assigned higher
priorities than all other types of kernel
threads
Linux Tasks
Linux Threads
Linux Namespaces
 A namespace enables a process to have a different view of the
system than other processes that have other associated
namespaces
 One of the overall goals is to support the implementation of
control groups, cgroups), a tool for lightweight virtualization that
provides a process or group of processes with the illusion that
they are the only processes on the system
 There are currently six namespaces in Linux
 mnt
 pid
 net
 ipc
 uts
 user
Android Process and
Thread Management
 An Android application is the software that
implements an app
 Each Android application consists of one or more
instance of one or more of four types of application
components
 Each component performs a distinct role in the overall
application and even by other applications
 Four types of components:
 Activities
 Services
 Content providers
 Broadcast receivers
Processes and
Threads
 A precedence
hierarchy is used to
determine which
process or processes to
kill in order to reclaim
needed resources
 Processes are killed
beginning with the
lowest precedence first
 The levels of the
hierarchy, in
descending order of
precedence are:
Mac OS X Grand Central
Dispatch (GCD)
 Provides a pool of available threads
 Designers can designate portions of
applications, called blocks, that can be
dispatched independently and run
concurrently
 Concurrency is based on the number of
cores available and the thread capacity of
the system
Block
A simple extension to a language
 A block defines a self-contained unit of
work
 Enables the programmer to encapsulate
complex functions
 Scheduled and dispatched by queues
 Dispatched on a first-in-first-out basis
 Can be associated with an event source,
such as a timer, network socket, or file
descriptor
Summary
 Processes and threads  Solaris thread and SMP
 Multithreading management
 Thread functionality
 Multithreaded architecture
 Motivation
 Types of threads  Process structure
 User level and kernel level  Thread execution
threads  Interrupts as threads
 Multicore and multithreading  Linux process and thread
management
 Windows 8 process and
 Tasks/threads/namespaces
thread management
 Changes in Windows 8  Android process and thread
 Windows process management
 Process and thread objects  Android applications
 Multithreading  Activities
 Thread states  Processes and threads
 Support for OS subsystems  Mac OS X grand central dispatch

You might also like