Chapter 4: Threads. Overview Multithreading Models Threading Issues Pthreads Windows XP Threads.

Slides:



Advertisements
Similar presentations
OPERATING SYSTEMS Threads
Advertisements

Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 AE4B33OSS Chapter 4: Threads Overview Multithreading Models Threading Issues Pthreads Windows.
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.
Threads.
Chapter 5 Threads os5.
Modified from Silberschatz, Galvin and Gagne ©2009 Lecture 7 Chapter 4: Threads (cont)
Day 10 Threads. Threads and Processes  Process is seen as two entities Unit of resource allocation (process or task) Unit of dispatch or scheduling (thread.
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 – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Based on Silberschatz, Galvin and Gagne  2009 Threads Definition and motivation Multithreading Models Threading Issues Examples.
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 4: Threads Dr. Mohamed Hefeeda.
Threads CSCI 444/544 Operating Systems Fall 2008.
Threads. Processes and Threads  Two characteristics of “processes” as considered so far: Unit of resource allocation Unit of dispatch  Characteristics.
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 &
Threads Chapter 4. Modern Process & Thread –Process is an infrastructure in which execution takes place  (address space + resources) –Thread is a program.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Multithreaded Programming.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 4: Threads Overview Multithreading Models Threading Issues.
Chapter 51 Threads Chapter 5. 2 Process Characteristics  Concept of Process has two facets.  A Process is: A Unit of resource ownership:  a virtual.
Processes Part I Processes & Threads* *Referred to slides by Dr. Sanjeev Setia at George Mason University Chapter 3.
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.
國立台灣大學 資訊工程學系 Chapter 4: Threads. 資工系網媒所 NEWS 實驗室 Objectives To introduce the notion of a thread — a fundamental unit of CPU utilization that forms the.
Chapter 4: Threads. From Processes to Threads 4.3 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Threads.
Thread. A basic unit of CPU utilization. It comprises a thread ID, a program counter, a register set, and a stack. It is a single sequential flow of control.
Chapter 4: Threads. 4.2CSCI 380 Operating Systems Chapter 4: Threads Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux.
1 Lecture 4: Threads Operating System Fall Contents Overview: Processes & Threads Benefits of Threads Thread State and Operations User Thread.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
Multithreading Allows application to split itself into multiple “threads” of execution (“threads of execution”). OS support for creating threads, terminating.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 4 Operating Systems.
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.
Lecture 5: Threads process as a unit of scheduling and a unit of resource allocation processes vs. threads what to program with threads why use threads.
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.
Chapter 4: Threads.
Chapter 4: Multithreaded Programming. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts What is Thread “Thread is a part of a program.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Department of Computer Science and Software Engineering
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Saurav Karmakar. Chapter 4: Threads  Overview  Multithreading Models  Thread Libraries  Threading Issues  Operating System Examples  Windows XP.
Operating System Concepts
Chapter 4: Threads 羅習五. Chapter 4: Threads Motivation and Overview Multithreading Models Threading Issues Examples – Pthreads – Windows XP Threads – Linux.
Lecturer 3: Processes multithreaded Operating System Concepts Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess.
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
Threads Overview Benefits, User and Kernel Threads.
OPERATING SYSTEM CONCEPT AND PRACTISE
Chapter 4: Multithreaded Programming
Chapter 4 Threads.
Chapter 4: Threads 羅習五.
Chapter 4: Threads.
Operating System Concepts
Chapter 4: Threads.
Chapter 4: Threads.
OPERATING SYSTEMS Threads
Modified by H. Schulzrinne 02/15/10 Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Presentation transcript:

Chapter 4: Threads

Overview Multithreading Models Threading Issues Pthreads Windows XP Threads

What is a thread? One sequence of control in a process  One process may have multiple threads  Multithreads in a process mean multiple sequences of control  Each thread has its own PC, stack & a register set  Threads belonging to a process share the address space and all the resources of the process, i.e., code, data, open files,... Entity for CPU utilization Concurrent processing  Only one thread can run at a time in a single processor system  Quickly switch between threads  Exploit multiprocessor archictecture if available

Single vs. Multiple Thread(s) of Control

Benefits: Why multithreads rather than multi-processes? Concurrent processing for much less overhead  Much less resource consumption for thread creation due to resource sharing among the threads belonging to one process No separate address space, code & data sections, or OS resources need to be allocated for each thread A thread only needs a separate PC, a stack, and storage space to copy register values

Benefits: Why multithreads rather than multi-processes? Context swithiching between threads is more efficient than switching btwn processes  Just save & restore the PC, stack, and register values of the two corresponding threads Synchronization btwn threads is easier & faster than that btwn processes  Threads of a process share the same address space;thus, they can directly pass data between them through variables  Processes have to communicate via IPC (Inter Process Communication) that is more complex and slower

User-Level vs. Kernel-Level Threads What are they? How they are different? Pros & Cons

User-Level Threads Threads are implemented by user-level libraries rather than by system calls No need to call OS for switching btwn threads Kernel knows nothing about user-level threads

Advantages of User-Level Threads Thread package can be implemented on top of an OS that may not support threads No need to modify OS Each thread is defined in user space  No need for kernel to keep the full TCB (Thread Control Block) for each & every thread No kernel interevention for thread creation, context switches, and synchronization – Fast and Efficient

Disadvantages of User-Level Threads Lack of coordination between threads & OS kernel  A process gets one time slice no matter how many threads it has  Each thread needs to pass control to other threads The entire process will block in the kernel if only one thread blocks, e.g., for I/O  There could be executable threads in the processes, but kernel has no idea about the user-level threads; it simply sees processes

Kernel Threads Supported by kernel Kernel manages not only processes but also threads Kernel provides system calls to create & manage threads

Advantages of Kernel Threads Kernel has full knowledge of all threads Better scheduling is possible  For example, give a large time slice to a process with many threads If a thread of a multithreaded process blocks, run another thread of the process rather than blocking the entire process Kernel routines can be multithreaded

Disadvantages of Kernel Threads Slow & inefficient  Switching btwn two threads in a single process involves the kernel (2 user-kernel mode switches)  Orders of magnitude slower than user-level threads Kernel has to manage both processes and threads  Store & maintain every PCB and TCB  Large overhead  Increased kernel complexity

Thread Package Design Example: Solaris User-level threads LWP – Virtual Processor Kernel thread for each LWP A kernel thread can be pinned to a CPU

Other Multithreading Issues

Thread Pools Create a number of threads in a pool where they await work Advantages:  Usually slightly faster to service a request with an existing thread than creating a new thread  Allows the number of threads in the application(s) to be bound to the size of the pool

Thread Specific Data Allows each thread to have its own copy of data Useful when you do not have control over the thread creation process (i.e., when using a thread pool)

Pthreads A POSIX standard (IEEE c) 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) You will use it for a programming assignment

End of Chapter 4