A. Frank - P. Weisberg Operating Systems Introduction to Tasks/Threads.

Slides:



Advertisements
Similar presentations
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Advertisements

Chapter 4 Threads Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William.
Threads, SMP, and Microkernels
Threads, SMP, and Microkernels Chapter 4. Process Resource ownership - process is allocated a virtual address space to hold the process image Scheduling/execution-
Chapter 4 Threads, SMP, and Microkernels Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design.
Computer Systems/Operating Systems - Class 8
Threads Irfan Khan Myo Thein What Are Threads ? a light, fine, string like length of material made up of two or more fibers or strands of spun cotton,
1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.
1 Chapter 4 Threads Threads: Resource ownership and execution.
Threads, SMP, and Microkernels
Threads. Processes and Threads  Two characteristics of “processes” as considered so far: Unit of resource allocation Unit of dispatch  Characteristics.
1 Threads Chapter 4 Reading: 4.1,4.4, Process Characteristics l Unit of resource ownership - process is allocated: n a virtual address space to.
Threads Chapter 4. Modern Process & Thread –Process is an infrastructure in which execution takes place  (address space + resources) –Thread is a program.
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.
Chapter 4 Threads, SMP, and Microkernels Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E.
9/13/20151 Threads ICS 240: Operating Systems –William Albritton Information and Computer Sciences Department at Leeward Community College –Original slides.
1 Lecture 4: Threads Operating System Fall Contents Overview: Processes & Threads Benefits of Threads Thread State and Operations User Thread.
Multithreading Allows application to split itself into multiple “threads” of execution (“threads of execution”). OS support for creating threads, terminating.
Threads, SMP, and Microkernels Chapter 4. 2 Outline n Threads n Symmetric Multiprocessing (SMP) n Microkernel n Linux Threads.
Operating System 4 THREADS, SMP AND MICROKERNELS
Threads, Thread management & Resource Management.
Chapter 4 Threads, SMP, and Microkernels Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design.
1 Threads, SMP, and Microkernels Chapter 4. 2 Focus and Subtopics Focus: More advanced concepts related to process management : Resource ownership vs.
Processes and Threads Processes have two characteristics: – Resource ownership - process includes a virtual address space to hold the process image – Scheduling/execution.
Threads, SMP, and Microkernels Chapter 4. Process Resource ownership - process is allocated a virtual address space to hold the process image Scheduling/execution-
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 13 Threads Read Ch 5.1.
Threads G.Anuradha (Reference : William Stallings)
1 Threads, SMP, and Microkernels Chapter 4. 2 Process Resource ownership: process includes a virtual address space to hold the process image (fig 3.16)
1 Threads, SMP, and Microkernels Chapter Multithreading Operating system supports multiple threads of execution within a single process MS-DOS.
1 Lecture 4: Threads Advanced Operating System Fall 2010.
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 ©2013 Operating System Concepts – 9 th Edition Chapter 4: Threads.
Department of Computer Science and Software Engineering
Operating Systems: Internals and Design Principles
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Processes and Threads.
Module 2.0: Threads.
Processes & Threads Introduction to Operating Systems: Module 5.
Threads, Thread management & Resource Management.
Threads-Process Interaction. CONTENTS  Threads  Process interaction.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 4: Threads.
Chapter 4 Threads, SMP, and Microkernels Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-2: Threads Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
1 Threads, SMP, and Microkernels Chapter 4. 2 Process Resource ownership - process includes a virtual address space to hold the process image Scheduling/execution-
Threads, SMP, and Microkernels Chapter 4. Processes and Threads Operating systems use processes for two purposes - Resource allocation and resource ownership.
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
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Chapter 4: Threads Modified by Dr. Neerja Mhaskar for CS 3SH3.
Threads Some of these slides were originally made by Dr. Roger deBry. They include text, figures, and information from this class’s textbook, Operating.
DISTRIBUTED SYSTEMS Principles and Paradigms Second Edition ANDREW S
Chapter 4: Threads.
Processes and threads.
Processes and Threads Processes and their scheduling
Chapter 4: Multithreaded Programming
Chapter 4 Threads.
Operating System Concepts
Operating Systems (CS 340 D)
Chapter 4: Threads.
Threads, SMP, and Microkernels
Chapter 4: Threads.
Threads Chapter 4.
Lecture 4- Threads, SMP, and Microkernels
Threads and Concurrency
Threads Chapter 4.
CHAPTER 4:THreads Bashair Al-harthi OPERATING SYSTEM
Multithreaded Programming
Operating Systems (CS 340 D)
Prof. Leonardo Mostarda University of Camerino
Presentation transcript:

A. Frank - P. Weisberg Operating Systems Introduction to Tasks/Threads

2 A. Frank - P. Weisberg Process Characteristics (1) Unit of resource ownership – process is allocated: –an address space to hold the process image. –control of some resources (files, I/O devices...). Unit of dispatching – process is an execution path through one or more programs: –execution may be interleaved with other process. –the process has an execution state and a dispatching priority.

3 A. Frank - P. Weisberg Process Characteristics (2) These two characteristics are treated independently by some recent OSs: 1.The unit of resource ownership is usually referred to as a Task or (for historical reasons) also as a Process. 2.The unit of dispatching is usually referred to a Thread or a Light-Weight Process (LWP). A traditional Heavy-Weight Process (HWP) is equal to a task with a single thread. Several threads can exist in the same task. –Multithreading - The ability of an OS to support multiple, concurrent paths of execution within a single process.

4 A. Frank - P. Weisberg The Process vs. Thread Model (a) Three processes each with one thread. (b) One process with three threads.

5 A. Frank - P. Weisberg Threads 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 –Spell checking –Answer a network request Process creation is heavy-weight while thread creation is light- weight. Can simplify code, increase efficiency. Kernels are generally multithreaded.

6 A. Frank - P. Weisberg Tasks/Processes and Threads (1) Task Items (shared by all threads of task): –address space which holds the process image –global variables –protected access to files, I/O and other resources Thread Items: –an execution state (Running, Ready, etc.) –program counter, register set –execution stack –some per-thread static storage for local variables –saved thread context when not running

7 A. Frank - P. Weisberg Tasks/Processes and Threads (2)

8 A. Frank - P. Weisberg Each thread has its own stack

9 A. Frank - P. Weisberg Combinations of Threads and Processes

10 A. Frank - P. Weisberg Single and Multithreaded Processes

11 A. Frank - P. Weisberg Processes vs. Threads Creating and managing processes is generally regarded as an expensive task (fork system call). Making sure all the processes peacefully co-exist on the system is not easy (as concurrency transparency comes at a price). Threads can be thought of as an “execution of a part of a program (in user-space)”. Rather than make the OS responsible for concurrency transparency, it is left to the individual application to manage the creation and scheduling of each thread.

12 A. Frank - P. Weisberg Benefits of Threads (1) Responsiveness – may allow continued execution if part of process is blocked, especially important for user interfaces. Resource Sharing – threads share process resources, 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 and networked/distributed systems.

13 A. Frank - P. Weisberg Benefits of Threads (2) Threads allows parallel activity inside a single address space: –While one server thread is blocked and waiting, a second thread in the same task can run. –Less time to create and terminate a thread than a process (because we do not need another address space). –Less time to switch between two threads than between processes. –Inter-thread communication and synchronization is very fast.

14 A. Frank - P. Weisberg Examples of benefits of threads Example 1: Word Processor: –one thread displays menu and reads user input while another thread executes user commands and a third one writes to disk – the application is more responsive. Example 2: a File/Web server on a LAN: –It needs to handle several files/pages requests over a short period. –Hence more efficient to create (and destroy) a single thread for each request. –On a SMP machine: multiple threads can possibly be executing simultaneously on different processors.

15 A. Frank - P. Weisberg Thread usage example: Word Processor

16 A. Frank - P. Weisberg Thread usage example: Web Server

17 A. Frank - P. Weisberg Web Server Threads (a) Dispatcher thread (b) Worker thread

18 A. Frank - P. Weisberg Multithreaded Server Architecture

19 A. Frank - P. Weisberg Important Implications Two Important Implications: 1.Threaded applications often run faster than non- threaded applications (as context-switches between kernel and user-space are avoided). 2.Threaded applications are harder to develop (although simple, clean designs can help here). Additionally, the assumption is that the development environment provides a Threads Library for developers to use (most modern environments do).

20 A. Frank - P. Weisberg Application benefits of threads (1) Consider an application that consists of several independent parts that do not need to run in sequence. Each part can be implemented as a thread. Whenever one thread is blocked waiting for an I/O, execution could possibly switch to another thread of the same application (instead of blocking it and switching to another application).

21 A. Frank - P. Weisberg Application benefits of threads (2) Since threads within the same process share memory and files, they can communicate with each other without invoking the kernel. Therefore necessary to synchronize the activities of various threads so that they do not obtain inconsistent views of the current data.

22 A. Frank - P. Weisberg Pop-Up Threads

23 A. Frank - P. Weisberg Thread Characteristics Has an execution context/state. Thread context is saved when not running. Has an execution stack and some per-thread static storage for local variables. Has access to the memory address space and resources of its task: –all threads of a task share this. –when one thread alters a (non-private) memory item, all other threads (of the task) see that. –a file open with one thread, is available to others.

24 A. Frank - P. Weisberg Threads States Three key states: running, ready, blocked They have no suspend state because all threads within same task share the same address space –Indeed: suspending (i.e., swapping) a single thread involves suspending all threads of the same task. Termination of a task, terminates all threads within the task.

25 A. Frank - P. Weisberg Multithreading Example