OS-05
Transcript of OS-05
-
8/7/2019 OS-05
1/23
Prof. D.S.R. Murthy OS-5 Threads 1
Threads
OverviewMultithreading Models
Threading Issues
Pthreads
Solaris 2 Threads
Windows 2000 Threads
Linux Threads
Java Threads
-
8/7/2019 OS-05
2/23
Prof. D.S.R. Murthy OS-5 Threads 2
Overview
Thread
Light Weight Process (LWP).
Basic unit of CPU utilisation.
Comprises ofThread ID
Program Counter
Register Set
Stack
TypesUser Threads
Kernel Threads
-
8/7/2019 OS-05
3/23
Prof. D.S.R. Murthy OS-5 Threads 3
Overview
Single and Multithreaded Processes
-
8/7/2019 OS-05
4/23
Prof. D.S.R. Murthy OS-5 Threads 4
Overview
Benefits of Multithreading
ResponsivenessAllows program to continue running even if part of it is blocked or
performing lengthy operation.
Resource SharingShares memory and resources of the process.
EconomyMore economical to create and context switch threads.
Utilization of Multiprocessor ArchitecturesEach thread may be running in parallel on a different processor.
Increases concurrency.
-
8/7/2019 OS-05
5/23
Prof. D.S.R. Murthy OS-5 Threads 5
Overview
User Threads
Thread management
done by user-level threads library.
Fast to create and manage.
Examples
- POSIX Pthreads
- Mach C-threads- Solaris 2 UI-threads
-
8/7/2019 OS-05
6/23
Prof. D.S.R. Murthy OS-5 Threads 6
Overview
KernelThreads
Supported by the Kernel.
Slow to create and manage.
Examples
- Windows 95/98/NT/2000
- Solaris 2
- Tru64 UNIX (formerly Digital UNIX)
- BeOS
- Linux
-
8/7/2019 OS-05
7/23
Prof. D.S.R. Murthy OS-5 Threads 7
MultithreadingModels
Many-to-One ModelOne-to-One Model
Many-to-Many Model
-
8/7/2019 OS-05
8/23
Prof. D.S.R. Murthy OS-5 Threads 8
Multithreading Models
Many-to-One Model
Many user-level threads mappedto single kernel thread.
Used on systems that do not support kernel threads.
-
8/7/2019 OS-05
9/23
Prof. D.S.R. Murthy OS-5 Threads 9
Multithreading Models
One-to-One Model
Each user-level thread maps to kernel thread.Provides more concurrency.
Allows multiple threads to run in parallelon multiprocessors.
Drawback
Creating user thread requires creating the corresponding kernel thread.
Examples- Windows 95/98/NT/2000
- OS/2
-
8/7/2019 OS-05
10/23
Prof. D.S.R. Murthy OS-5 Threads 10
Multithreading Models
Many-to-Many Model
Allows many userlevel threads to be mapped to many kernel threads.Allows the operating system to create a sufficient no. of kernel threads.
Examples
Windows NT/2000 with the ThreadFiberpackage
Solaris 2
IRIX HP-UX
Tru64 UNIX
-
8/7/2019 OS-05
11/23
Prof. D.S.R. Murthy OS-5 Threads 11
Threading Issues
fork and exec System Calls
Thread Cancellation
Signal Handling
Thread Pools
Thread Specific Data
-
8/7/2019 OS-05
12/23
Prof. D.S.R. Murthy OS-5 Threads 12
Threading Issues
fork and exec System Calls
Versions of fork System call
1. Duplicates all threads.
2. Duplicates only the threadthat invokedthe fork system call.
exec System callreplaces entire process.
-
8/7/2019 OS-05
13/23
Prof. D.S.R. Murthy OS-5 Threads 13
Threading Issues
Thread Cancellation
Task ofterminating thread(target thread) before it has completed.
Asynchronous cancellationOne thread immediately terminates the target thread.
Deferred cancellationTarget thread periodically checks if it should terminate,
allowing the target thread an opportunity to terminate itself
in an orderly fashion.
-
8/7/2019 OS-05
14/23
Prof. D.S.R. Murthy OS-5 Threads 14
Threading Issues
SignalHandling
Signal
Notifies process a particular event occurred.
Received either synchronously or asynchronously.
1. Signal generated by the occurrence of a particular event.
2. Generated signal delivered to a process.
3. Once delivered, the signal must be handled.
4. Default signal handler or user-defined signal handler handles every signal.
-
8/7/2019 OS-05
15/23
Prof. D.S.R. Murthy OS-5 Threads 15
Threading Issues
Thread Pools
Create no. of threads at process startup
and place them into a pool.
Benefits It is usually faster to service a request with an existing thread
than waiting to create a thread.
A thread pool limits the no. of threads
that exist at any one point.
-
8/7/2019 OS-05
16/23
Prof. D.S.R. Murthy OS-5 Threads 16
Threading Issues
ThreadSpecific Data
Each thread
needs its own copy of certain data.
Examples
- Win32
- Pthreads
- Java
-
8/7/2019 OS-05
17/23
Prof. D.S.R. Murthy OS-5 Threads 17
Pthreads
POSIX standard (IEEE 1003.1c)
Application Program Interface (API)
for thread creation and synchronization.
specifies behavior ofthe threadlibrary;
implementation is up to development of the library.
Common in
UNIX operating systems.
-
8/7/2019 OS-05
18/23
Prof. D.S.R. Murthy OS-5 Threads 18
Solaris 2 Threads
Version of UNIX
with supportforthreads at the kerneland userlevels.
Implements
Pthread API.
many-to-many model.
-
8/7/2019 OS-05
19/23
Prof. D.S.R. Murthy OS-5 Threads 19
Solaris 2 Threads
Solaris Process
-
8/7/2019 OS-05
20/23
Prof. D.S.R. Murthy OS-5 Threads 20
Windows 2000 Threads
Implements
Win32 API.
one-to-one mapping.
Each thread contains
- Thread ID
- Register set
- Separate user and kernel stacks
- Private data storage area
-
8/7/2019 OS-05
21/23
Prof. D.S.R. Murthy OS-5 Threads 21
Linux Threads
Refers as tasks rather than threads.
Thread creation
done through clone system call.
Clone system call
allows a child task to sharethe address space of the parent task (process).
Does not support multithreading.
-
8/7/2019 OS-05
22/23
Prof. D.S.R. Murthy OS-5 Threads 22
Java Threads
Created byy Extending Thread class.
y Implementing the Runnable interface.
Managed byJavaVirtual Machine (JVM).
-
8/7/2019 OS-05
23/23
Prof. D.S.R. Murthy OS-5 Threads 23
Java Threads
Java ThreadStates