Download presentation
Presentation is loading. Please wait.
Published byEustacia Hunter Modified over 8 years ago
1
Lecture 5
2
Example for periority The average waiting time : 6+0+16+18+1= 41/5= 8.2
3
THREAD
4
Overview Process : single thread or multi thread Thread — a fundamental unit of CPU utilization that forms the basis of multithreaded computer systems Comprises : – Thread ID – Program counter – Register set – Stack Share with other threads with the same process : (Code – Data – Resources )
5
Thread Example Web browser – Thread to display image – Thread retrieves data from network Word – Thread display graphics – Thread keystrokes
6
Single and Multithreaded Processes
7
Benefits Responsiveness – Allow interactive application to continue running if part of, is blocked Resource Sharing – Threads share code and data by default from process but multi-process needs writing code for share memory or message passing Economy – Allocating memory and resources for process creation is costly. – In new process : more overhead, more time consuming and management Scalability – In multi processor parallelism multithreading can be greatly increased in a multiprocessor architecture,
8
Multicore Programming – New Trend : multi-core on a single chip, each core is single process for operating system – Multi core : means parallelism – Multi-core : needs designers of operating system write scheduling algorithms, use multi processing
9
Multicore Programming Multi-core systems putting pressure on programmers, challenges include 5 points: – Dividing activities – Balance – Data splitting – Data dependency – Testing and debugging
10
Multicore Programming Dividing activities – Find areas can be divided into separate and concurrent tasks Balance – Tasks perform equal work of equal value Data splitting – As application … data accessed by tasks must be divided to run on separate core. Data dependency – The data accessed by the tasks must be examined for dependencies between two or more tasks. Testing and debugging – Testing and debugging such concurrent programs is inherently more difficult than testing and debugging single-threaded applications.
11
Concurrent Execution on a Single-core System
12
Parallel Execution on a Multicore System
13
Multithread modeling User threads : manage with out kernel Kernel thread: manage by OS User threads are supported above the kernel and are managed without kernel support, whereas kernel threads are supported and managed directly by the operating system.
14
User Threads Thread management done by user-level threads library Three primary thread libraries: – POSIX Pthreads – Win32 threads – Java threads
15
Kernel Threads Supported by the Kernel Examples – Windows XP/2000 – Solaris – Linux – Tru64 UNIX – Mac OS X
16
Multithreading Models Many-to-One One-to-One Many-to-Many
17
Many-to-One Many user-level threads mapped to single kernel thread User thread library in user space Because one thread can access a kernel at a time, multi thread no parallelism in multi processor
18
Many-to-One Model
19
One-to-One Each user-level thread maps to kernel thread - allow parallelism if multiprocessor only draw back: create user thread needs to create kernel thread Examples – Windows NT/XP/2000 – Linux – Solaris 9 and later
20
One-to-one Model
21
Many-to-Many Model Allows many user level threads to be mapped to many kernel threads Allows the operating system to create a sufficient number of kernel threads No true concurrency because kernel can schedule only one thread at a time The number of kernel threads may be specific to either a particular application or particular machine Windows NT/2000 with the ThreadFiber package
22
Many-to-Many Model
23
Two-level Model Similar to M:M, except that it allows a user thread to be bound to kernel thread
24
Two-level Model
25
Thread Libraries Thread library provides programmer with API for creating and managing threads Two primary ways of implementing – Library entirely in user space – Kernel-level library supported by the OS
26
Pthreads May be provided either as user-level or kernel-level A POSIX standard (IEEE 1003.1c) API for thread creation and synchronization 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)
27
win32Threads In c program …. Window.h Is a kernel –level library available on windows system
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.