Introduction to threads

Slides:



Advertisements
Similar presentations
Multithreading Overview Multithreading Models Threading Issues
Advertisements

Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Multithreaded Programming.
Threads. Objectives To introduce the notion of a thread — a fundamental unit of CPU utilization that forms the basis of multithreaded computer systems.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
國立台灣大學 資訊工程學系 Chapter 4: Threads. 資工系網媒所 NEWS 實驗室 Objectives To introduce the notion of a thread — a fundamental unit of CPU utilization that forms the.
Modified from Silberschatz, Galvin and Gagne ©2009 Lecture 7 Chapter 4: Threads (cont)
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 4: Threads CS 170 TY, Sept 2011.
4.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 4 Multithreaded Programming Objectives Objectives To introduce a notion of.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Based on Silberschatz, Galvin and Gagne  2009 Threads Definition and motivation Multithreading Models Threading Issues Examples.
Chapter 4: Multithreaded Programming. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Objectives To introduce a notion of a thread.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Objectives Thread definitions and relationship to process Multithreading.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Chapter 4: Threads READ 4.1 & 4.2 NOT RESPONSIBLE FOR 4.3 &
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Multithreaded Programming.
14.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 4: Threads.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Operating System Principles Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Chapter 4: Threads. 4.2 Chapter 4: Threads Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads Java Threads.
14.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 4: Threads.
Silberschatz, Galvin and Gagne ©2011Operating System Concepts Essentials – 8 th Edition Chapter 4: Threads.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 4: Threads Overview Multithreading Models Threading Issues.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 4: Threads Modified from the slides of the text book. TY, Sept 2010.
Multithreaded Programing. Outline Overview of threads Threads Multithreaded Models  Many-to-One  One-to-One  Many-to-Many Thread Libraries  Pthread.
Lecture 3 Threads Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
Saurav Karmakar. Chapter 4: Threads  Overview  Multithreading Models  Thread Libraries  Threading Issues  Operating System Examples  Windows XP.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 4: Threads.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
1 Chapter 5: Threads Overview Multithreading Models & Issues Read Chapter 5 pages
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Lecture 5. Example for periority The average waiting time : = 41/5= 8.2.
14.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 4: Multithreaded Programming.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Threads Overview Benefits, User and Kernel Threads.
Chapter 4: Threads Modified by Dr. Neerja Mhaskar for CS 3SH3.
Chapter 4: Multithreaded Programming
Client-Server Communication
OPERATING SYSTEM CONCEPT AND PRACTISE
Chapter 4: Threads.
Chapter 5: Threads Overview Multithreading Models Threading Issues
Chapter 4: Multithreaded Programming
Nadeem MajeedChoudhary.
Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Operating System Concepts
Chapter 4: Threads.
Chapter 4 Multithreading programming
Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Modified by H. Schulzrinne 02/15/10 Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
CHAPTER 4:THreads Bashair Al-harthi OPERATING SYSTEM
Multithreaded Programming
Chapter 4: Threads & Concurrency
Chapter 4: Threads.
Chapter 4: Threads.
Q:(a)Describe the action for a kernel to context switching for threads (b)why it is faster than processes?
Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Presentation transcript:

Introduction to threads CSSE 332 Operating Systems Rose-Hulman Institute of Technology 1

Thread overview A basic unit of CPU utilization Comprises A thread ID A program counter A register set A stack Shares with other threads of the same process Code section Data section Other OS resources (open files, signals, etc) A traditional process has a single thread of control. If a process has more than one thread of control, it can perform multiple tasks at a time. 2

Single and multithreaded processes 3

Motivation for threads Many modern software packages are multithreaded A single app may be required to perform multiple similar tasks Most modern OS kernels are now multithreaded Web-browser may have one thread to display images or text, while another thread retrieves data from the network. A web server may have several requests from clients requesting web pages, texts, images, sound files, etc. Kernel has threads for managing devices, handling interrupts, managing free space (LINUX does this last thing) 4

Benefits of multithreading Responsiveness (to user) Resource sharing Economy Scalability Have students think-pair-share on this. Interactive application  program can continue running even if parts of it are blocked. No need of message passing or shared memory techniques to share code and data and files, etc. It is more economical to create and context switch threads than processes (processes are heavyweight entities) Multithreading on a multi-CPU machine increases parallelism 5

Multicore programming Multicore systems put pressure on programmers Challenges include Dividing activities Balance Data splitting Data dependency Testing and debugging Do think-pair-share on why these are challenges Examining app to find areas that can be divided into separate, concurrent tasks that can run on individual cores Ensuring that tasks do equal work of equal value Data accessed and manipulated by tasks must be divided to run on separate cores Does one task depend on data from another task? The tasks must be synchronized in this case Different execution paths --- testing and debugging inherently more difficult. 6

Multithreaded server architecture The main thread waits for requests from clients, creates thread to service request, and resumes waiting for requests.

Concurrent execution on single-core system

Parallel execution on multicore system

User Threads Thread management done by user-level threads library Three primary thread libraries: POSIX Pthreads Win32 threads Java threads A thread library provides the programmer with an API for creating and managing threads POSIX library may be provided as either user or kernel level library Win32 is kernel level library available on Windows systems Java allows threaded management to be done directly in Java program but the thread API is generally implemented using the thread library on host system 10

Kernel Threads Supported by the Kernel Examples Windows XP/2000 Solaris Linux Tru64 UNIX Mac OS X Threading model supported by the kernel. Needed for true parallelism on multiple CPUs. 11

Multithreading Models Many-to-One One-to-One Many-to-Many Multithreading models answer the question of how do we map user threads to kernel threads in order to experience parallelism 12

Many-to-One Many user-level threads mapped to single kernel thread Examples: Solaris Green Threads GNU Portable Threads Thread management is done by thread library in user space. Efficient thread management but no parallelism. If thread blocks, process blocks. 13

Many-to-One Model Thread management is done by thread library in user space. 14

One-to-One Each user-level thread maps to kernel thread Examples Windows NT/XP/2000 Linux Solaris 9 and later Each user thread is mapped to a kernel thread  true parallelism LINUX threads are not the same as POSIX threads 15

One-to-one Model Only drawback: creating a user thread requires the overhead of creating a kernel thread 16

Many-to-Many Allows many user level threads to be mapped to many kernel threads Allows the operating system to create a sufficient number of kernel threads Solaris prior to version 9 Windows NT/2000 with the ThreadFiber package 17

Many-to-Many Model 18

Two-level Model Similar to M:M, except that it allows a user thread to be bound to kernel thread Examples IRIX HP-UX Tru64 UNIX Solaris 8 and earlier 19

Two-level Model 20