Ceng 334 - Operating Systems 2.5-1 Chapter 2.5 : Threads Process concept  Process scheduling  Interprocess communication  Deadlocks  Threads.

Slides:



Advertisements
Similar presentations
1 Processes and Threads Creation and Termination States Usage Implementations.
Advertisements

Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
1 Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
Chapter 5 Threads os5.
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,
Chapter 4: Threads. Overview Multithreading Models Threading Issues Pthreads Windows XP Threads.
1 Threads CSCE 351: Operating System Kernels Witawas Srisa-an Chapter 4-5.
Threads Section 2.2. Introduction to threads A thread (of execution) is a light-weight process –Threads reside within processes. –They share one address.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
Avishai Wool lecture Priority Scheduling Idea: Jobs are assigned priorities. Always, the job with the highest priority runs. Note: All scheduling.
Silberschatz, Galvin, and Gagne  Applied Operating System Concepts Module 5: Threads 9/29/03+ Overview Benefits User and Kernel Threads Multithreading.
Threads - Definition - Advantages using Threads - User and Kernel Threads - Multithreading Models - Java and Solaris Threads - Examples - Definition -
Threads CSCI 444/544 Operating Systems Fall 2008.
Chapter 2 Processes and Threads Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved
1 Chapter 4 Threads Threads: Resource ownership and execution.
Threads. Processes and Threads  Two characteristics of “processes” as considered so far: Unit of resource allocation Unit of dispatch  Characteristics.
Process Concept An operating system executes a variety of programs
A. Frank - P. Weisberg Operating Systems Introduction to Tasks/Threads.
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.
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.
1 Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
Processes and Threads.
1 Process States (1) Possible process states –running –blocked –ready Transitions between states shown.
Chapter 4: Threads. From Processes to Threads 4.3 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Threads.
Multithreading Allows application to split itself into multiple “threads” of execution (“threads of execution”). OS support for creating threads, terminating.
Process Management. Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication.
Operating System 4 THREADS, SMP AND MICROKERNELS
Threads, Thread management & Resource Management.
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 2 Processes and Threads Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
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)
CE Operating Systems Lecture 7 Threads & Introduction to CPU Scheduling.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
ITFN 3601 Introduction to Operating Systems Lecture 3 Processes, Threads & Scheduling Intro.
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.
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.
1 Chapter 2.5 : Threads Process concept  Process concept  Process scheduling  Process scheduling  Interprocess communication  Interprocess communication.
Threads-Process Interaction. CONTENTS  Threads  Process interaction.
Threads. Readings r Silberschatz et al : Chapter 4.
Cs431-cotter1 Processes and Threads Tanenbaum 2.1, 2.2 Crowley Chapters 3, 5 Stallings Chapter 3, 4 Silberschaz & Galvin 3, 4.
Shahriar Pirnia Operating system سيستم عامل.
Processes and Threads MICROSOFT.  Process  Process Model  Process Creation  Process Termination  Process States  Implementation of Processes  Thread.
Operating Systems Unit 2: – Process Context switch Interrupt Interprocess communication – Thread Thread models Operating Systems.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-2: Threads Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Operating System Concepts
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-
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Lecturer 3: Processes multithreaded Operating System Concepts Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess.
Processes Chapter 3. Processes in Distributed Systems Processes and threads –Introduction to threads –Distinction between threads and processes Threads.
7/9/ Realizing Concurrency using Posix Threads (pthreads) B. Ramamurthy.
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 2 Processes and Threads Today 2.1 Processes 2.2 Threads
Chapter 4 Threads.
Threads & multithreading
Operating System Concepts
Operating Systems (CS 340 D)
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Threads Chapter 4.
Chapter 2 Processes and Threads 2.1 Processes 2.2 Threads
Operating Systems Threads 1.
Thread Model for Work Unit
Process Management -Compiled for CSIT
What is a Thread? A thread is similar to a process, but it typically consists of just the flow of control. Multiple threads use the address space of a.
Threads CSE 2431: Introduction to Operating Systems
CS Introduction to Operating Systems
Presentation transcript:

Ceng Operating Systems Chapter 2.5 : Threads Process concept  Process scheduling  Interprocess communication  Deadlocks  Threads

Ceng Operating Systems These lecture notes have been adapted from How to program with threads An introduction to multithreaded programming By Bil Lewis and Daniel J. Berg and Tanenbaum slides

Ceng Operating Systems Processes & Threads Processes and threads are related concepts A process is a kernel-level entity –Process structure can only be accessed through system calls A thread (or a lightweight process) is a user-level entity –The thread structure is in user space –It is accessed directly with the thread library calls, which are just normal user-level functions (threads do not use system calls)

Ceng Operating Systems Threads The Thread Model (1) (a) Three processes each with one thread (b) One process with three threads

Ceng Operating Systems The Thread Model (2) Items shared by all threads in a process Items private to each thread

Ceng Operating Systems The Thread Model (3) Each thread has its own stack

Ceng Operating Systems Process and Thread Data Structures Kernel Space User Space PCB CodeDataStack TCB1TCB2TCB3

Ceng Operating Systems Characteristics of Threads The TCB (thread control block) consist of –program counter –register set –stack space Thus the TCB is a reduced PCB A traditional process is equal to a task with one thread All threads in a process share the state of that process

Ceng Operating Systems Characteristics of Threads (Cont.) They reside in the exact same memory space (user memory), see the same code and data When one thread alters a process variable (say, the working directory), all the others will see the change when they next access it If one thread opens a file to read it, all the other threads can also read from it.

Ceng Operating Systems Characteristics of Threads (Cont.) Because no system calls are involved, threads are fast There are no kernel structures affected by the existence of threads in a program, so no kernel resources are consumed -- threads are cheap The kernel doesn't even know that threads exist

Ceng Operating Systems Thread Scheduling (1) Possible scheduling of user-level threads 50-msec process quantum threads run 5 msec/CPU burst

Ceng Operating Systems Thread Scheduling (2) Possible scheduling of kernel-level threads 50-msec process quantum threads run 5 msec/CPU burst

Ceng Operating Systems Threads of a Task Threads Code segment Data segment Program Counter Threads Task

Ceng Operating Systems Implementing Threads in User Space A user-level threads package

Ceng Operating Systems Implementing Threads in the Kernel A threads package managed by the kernel

Ceng Operating Systems Hybrid Implementations Multiplexing user-level threads onto kernel- level threads

Ceng Operating Systems Single vs. Multiple Threads of Execution Start End Edit Document Print Document Single Thread Multiple Threads End Edit Document Start Print Document

Ceng Operating Systems Thread Usage (1) A word processor with three threads

Ceng Operating Systems Thread Usage (2) A multithreaded Web server

Ceng Operating Systems Thread Usage (3) Rough outline of code for previous slide (a) Dispatcher thread (b) Worker thread

Ceng Operating Systems Some Benefits of Writing Multithreaded Programs:  Performance gains from multiprocessing hardware (parallelism)  Increased application throughput  Increased application responsiveness  Enhanced process-to-process communications

Ceng Operating Systems Parallellism Different threads can run on different processors simultaneously with no special input from the user and no effort on the part of the programmer

Ceng Operating Systems Throughput When a traditional, single-threaded program requests a service from the operating system, it must wait for that service to complete, often leaving the CPU idle Multithreading provides progress even though one or more threads wait for an event as long as other threads are active

Ceng Operating Systems Responsiveness Blocking one part of a process need not block the whole process. Single-threaded applications that do something lengthy when a button is pressed typically display a "please wait" cursor and freeze while the operation is in progress If such applications were multithreaded, long operations could be done by independent threads, allowing the application to remain active and making the application more responsive to the user

Ceng Operating Systems Communications An application that uses multiple processes to accomplish its tasks can be replaced by an application that uses multiple threads to accomplish those same tasks Processes-to-process communication through traditional IPC (interprocess communications) facilities (e.g., pipes or sockets) The threaded application can use the inherently shared memory of the process