0% found this document useful (0 votes)
11 views20 pages

CS3451 Operating Systems Notes

Uploaded by

revicse
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views20 pages

CS3451 Operating Systems Notes

Uploaded by

revicse
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

ARASU ENGINEERING

COLLEGE
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

CS3451 – INTRODUCTION TO
OPERATING SYSTEMS
II YEAR / IV SEMESTER
Anna University Syllabus, 2021
Regulation
Prepared by
Mrs. V. Revathy
Assistant
Professor/ CSE
Thread Motivation
 Most modern applications are multithreaded
 Threads run within application
 Multiple tasks with the application can be implemented
by separate threads
 Update display
 Fetch data
Multithreaded
 Spell checking Server
Architecture
 Answer a network
request
 Process creation is heavy-weight while thread creation is
light- weight
 Can simplify code, increase efficiency
 Kernels are generally multithreaded

CS3451-IOS/ V. REVATHY / AP-CSE /AEC


Benefits
 Responsiveness – may allow continued execution if part
of process is blocked, especially important for user
interfaces
 Resource Sharing – threads share resources of process,
easier than shared memory or message passing
 Economy – cheaper than process creation, thread
switching lower overhead than context switching
 Scalability – process can take advantage
of multiprocessor
architectures

CS3451-IOS/ V. REVATHY / AP-CSE /AEC


Multicore Programming
 Multicore or multiprocessor systems putting pressure
on programmers, challenges include:
 Dividing activities
 Balance
 Data splitting
 Data dependency
 Testing and debugging
 Parallelism implies a system can perform more than one
task simultaneously
 Concurrency supports more than one task making progress
 Single processor / core, scheduler providing concurrency
Multicore Programming (Cont.)
Types of parallelism
Data parallelism – distributes subsets of the same
data across multiple cores, same operation on each
Task parallelism – distributing threads across
cores, each thread performing unique operation
As # of threads grows, so does
architectural support for threading
CPUs have cores as well as hardware threads
Consider Oracle SPARC T4 with 8 cores, and
8 hardware threads per core

CS3451-IOS/ V. REVATHY / AP-CSE /AEC


Single and Multithreaded Processes

CS3451-IOS/ V. REVATHY / AP-CSE /AEC


Amdahl’s Law
 Identifies performance gains from adding additional cores to
an application that has both serial and parallel components
 S is serial portion
 N processing cores
 That is, if application is 75% parallel / 25% serial, moving from 1
to 2 cores results in speedup of 1.6 times
 As N approaches infinity, speedup approaches 1 / S
 Serial portion of an application has disproportionate effect
on performance gained by adding additional cores
 But does the law take into account contemporary multicore
systems?

CS3451-IOS/ V. REVATHY / AP-CSE /AEC


User Threads and Kernel Threads
 User threads - management done by user-level threads library
 Three primary thread libraries:
 POSIX Pthreads
 Windows threads
 Java threads
 Kernel threads - Supported by the Kernel
 Examples – virtually all general purpose operating systems,
including:
Windows
Solaris
Linux
Tru64 UNIX
Mac OS X
CS3451-IOS/ V. REVATHY / AP-CSE /AEC
Multithreading Models

Many-to-One
 Many user-level threads mapped to single
kernel thread
 One thread blocking causes all to block
 Multiple threads may not run in parallel on
muticore system because only one may be
in kernel at a time
 Few systems currently use this model
 Examples:
 Solaris Green Threads
 GNU Portable Threads

CS3451-IOS/ V. REVATHY / AP-CSE /AEC


One-to-One Many-to-Many
 Each user-level thread  Allows many user level threads
maps to kernel thread to
be mapped to many
 Creating a user-level kernel
threads
thread creates a kernel  Allows the operating
thread system a to
create sufficient number of
 More concurrency kernel threads
 than
Number of threads per  Solaris prior to version
many-to-one
process sometimes restricted 9Windows with the
due to overhead ThreadFiber
 Examples: Windows, Linux & package
Solaris 9 and later

10
Two-level Model Thread Libraries
 Similar to M:M, except that it  Thread provide
allows a user to library
programme with s API for
thread be r creating and managin
bound to kernel threads g
thread  Two
 Examples primary ways
 IRIX implementing
 Library of
entirely use
 HP-UX in space r
 Tru64 UNIX  Kernel-level librar
 Solaris 8 and supported by the y
OS
earlier
Pthreads
 May be provided either as user-level or kernel-level
 A POSIX standard (IEEE 1003.1c) API for thread creation
and
synchronization
 Specification, not implementation
 API specifies behavior of the thread library, implementation is up to
development of the library
 Common in UNIX operating systems (Solaris, Linux, Mac OS X)

Pthreads Code for Joining 10 Threads


Pthreads Example

CS3451-IOS/ V. REVATHY / AP-CSE /AEC


Pthreads Example (Cont.)

CS3451-IOS/ V. REVATHY / AP-CSE /AEC


Windows Multithreaded C Program

CS3451-IOS/ V. REVATHY / AP-CSE /AEC


Windows Multithreaded C
Program

CS3451-IOS/ V. REVATHY / AP-CSE /AEC


Java
Threads
Java threads are managed by the JVM
Typically implemented using the threads
model provided by underlying OS
Java threads may be created
by:

Extending Thread class


Implementing the Runnable
interface
CS3451-IOS/ V. REVATHY / AP-CSE /AEC
Java Multithreaded Program
Java Multithreaded Program

CS3451-IOS/ V. REVATHY / AP-CSE /AEC


Thank You
CS3451-IOS/ V. REVATHY / AP-CSE /AEC

You might also like