Process Characteristics. Threads Chapter 4. Process Characteristics. Multithreading vs. Single threading

Similar documents
Threads Chapter 4. Reading: 4.1,4.4, 4.5

Threads Chapter 5 1 Chapter 5

Processes and Threads. Processes and Threads. Processes (2) Processes (1)

Process Characteristics

Chapter 3 Process Description and Control

Motivation. Threads. Multithreaded Server Architecture. Thread of execution. Chapter 4

Operating Systems: Internals and Design Principles. Chapter 4 Threads Seventh Edition By William Stallings

operating system Spring 2017 Prof.Dr. Hasan Balik Student Name : Walid.W. Ramadan mansour Student ID :

Threads, SMP, and Microkernels

For use by students enrolled in #71251 CSE430 Fall 2012 at Arizona State University. Do not use if not enrolled.

ECE519 Advanced Operating Systems

Operating System. Chapter 4. Threads. Lynn Choi School of Electrical Engineering

Threads, SMP, and Microkernels. Chapter 4

Operating Systems. Engr. Abdul-Rahman Mahmood MS, PMP, MCP, QMR(ISO9001:2000) alphapeeler.sf.net/pubkeys/pkey.htm

Lecture Topics. Announcements. Today: Threads (Stallings, chapter , 4.6) Next: Concurrency (Stallings, chapter , 5.

Multithreading. Reading: Silberschatz chapter 5 Additional Reading: Stallings chapter 4

CSCI-GA Operating Systems Lecture 3: Processes and Threads -Part 2 Scheduling Hubertus Franke

CSE 306/506 Operating Systems Threads. YoungMin Kwon

Chapter 4 Threads, SMP, and

Threads. studykorner.org

Threads. Still Chapter 2 (Based on Silberchatz s text and Nachos Roadmap.) 3/9/2003 B.Ramamurthy 1

Threads. CS3026 Operating Systems Lecture 06

Exercise (could be a quiz) Solution. Concurrent Programming. Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - IV Threads

Threads. Thread Concept Multithreading Models User & Kernel Threads Pthreads Threads in Solaris, Linux, Windows. 2/13/11 CSE325 - Threads 1

Chapter 4: Multi-Threaded Programming

4. Concurrency via Threads

Chapter 4: Threads. Operating System Concepts 9 th Edit9on

Threads Assistant Professor DCS Operating System Concepts

Processes and Threads

Page 1. Analogy: Problems: Operating Systems Lecture 7. Operating Systems Lecture 7

2017 Pearson Educa2on, Inc., Hoboken, NJ. All rights reserved.

Operating System 4 THREADS, SMP AND MICROKERNELS

COMP 346 WINTER Tutorial 2 SHARED DATA MANIPULATION AND SYNCHRONIZATION

OPERATING SYSTEM. Chapter 4: Threads

Chapter 4: Threads. Chapter 4: Threads

Yi Shi Fall 2017 Xi an Jiaotong University

Concurrency, Thread. Dongkun Shin, SKKU

DISTRIBUTED COMPUTER SYSTEMS

Process Scheduling Queues

Definition Multithreading Models Threading Issues Pthreads (Unix)

CS 450 Operating System Week 4 Lecture Notes

Operating Systems. Lecture 4. Nachos Appetizer

Roadmap. Concurrent Programming. Concurrent Programming. Motivation. Why Threads? Tevfik Ko!ar. CSC Systems Programming Fall 2010

Process Description and Control

I.-C. Lin, Assistant Professor. Textbook: Operating System Concepts 8ed CHAPTER 4: MULTITHREADED PROGRAMMING

Chapter 4: Threads. Chapter 4: Threads. Overview Multicore Programming Multithreading Models Thread Libraries Implicit Threading Threading Issues

Process Description and Control. Chapter 3

Processes. Process Management Chapter 3. When does a process gets created? When does a process gets terminated?

Lecture Contents. 1. Overview. 2. Multithreading Models 3. Examples of Thread Libraries 4. Summary

Today s Topics. u Thread implementation. l Non-preemptive versus preemptive threads. l Kernel vs. user threads

Operating Systems Overview. Chapter 2

Dr. D. M. Akbar Hussain DE5 Department of Electronic Systems

Thread Concept. Thread. No. 3. Multiple single-threaded Process. One single-threaded Process. Process vs. Thread. One multi-threaded Process

Multithreaded Programming Part II. CSE 219 Stony Brook University, Department of Computer Science

Multithreaded Programming

Operating Systems 2 nd semester 2016/2017. Chapter 4: Threads

Part V. Process Management. Sadeghi, Cubaleska RUB Course Operating System Security Memory Management and Protection

Processes, Threads, SMP, and Microkernels

Java Threads. Introduction to Java Threads

Chapter 4: Threads. Operating System Concepts 9 th Edition

Chapter 4: Threads. Operating System Concepts 9 th Edition

Chapter 4: Threads. Chapter 4: Threads

Motivation of Threads. Preview. Motivation of Threads. Motivation of Threads. Motivation of Threads. Motivation of Threads 9/12/2018.

Processes and Threads. Processes: Review

Threads. Threads The Thread Model (1) CSCE 351: Operating System Kernels Witawas Srisa-an Chapter 4-5

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

Announcements. Reading. Project #1 due in 1 week at 5:00 pm Scheduling Chapter 6 (6 th ed) or Chapter 5 (8 th ed) CMSC 412 S14 (lect 5)

CPS221 Lecture: Threads

Chapter 4: Processes. Process Concept

CSE 153 Design of Operating Systems Fall 2018

Chapter 4: Processes

Processes and Threads

Learning Outcomes. Processes and Threads. Major Requirements of an Operating System. Processes and Threads

CMSC 132: Object-Oriented Programming II. Threads in Java

Module 4: Processes. Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess Communication

Lecture 4: Threads; weaving control flow

Module 4: Processes. Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess Communication

Process Description and Control

CS 571 Operating Systems. Midterm Review. Angelos Stavrou, George Mason University

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

User Space Multithreading. Computer Science, University of Warwick

CSE 120 Principles of Operating Systems

CHAPTER 2: PROCESS MANAGEMENT

Processes. CS3026 Operating Systems Lecture 05

POSIX Threads: a first step toward parallel programming. George Bosilca

Announcement. Exercise #2 will be out today. Due date is next Monday

Last Class: CPU Scheduling. Pre-emptive versus non-preemptive schedulers Goals for Scheduling: CS377: Operating Systems.

Computer Systems II. First Two Major Computer System Evolution Steps

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

Computation Abstractions. Processes vs. Threads. So, What Is a Thread? CMSC 433 Programming Language Technologies and Paradigms Spring 2007

Major Requirements of an OS

Chapter 4: Threads. Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads Java Threads. Operating System Concepts

EI 338: Computer Systems Engineering (Operating Systems & Computer Architecture)

Chapter 4: Multithreaded Programming

OPERATING SYSTEMS. UNIT II Sections A, B & D. An operating system executes a variety of programs:

Processes and Threads

0. Course Overview. 8 Architecture models; network architectures: OSI, Internet and LANs; interprocess communication III. Time and Global States

Process Description and Control. Chapter 3

Lecture 2 Process Management

Note: Each loop has 5 iterations in the ThreeLoopTest program.

Transcription:

Process Characteristics Threads Chapter 4 Reading: 4.1,4.4, 4.5 Unit of resource ownership - process is allocated: a virtual 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 1 2 Process Characteristics These two characteristics are treated independently by some recent OS The unit of dispatching is usually referred to a thread or a lightweight process The unit of resource ownership is usually referred to as a process or task Multithreading vs. Single threading Multithreading: when the OS supports multiple threads of execution within a single process Single threading: when the OS does not recognize the concept of thread MS-DOS support a single user process and a single thread UNIX supports multiple user processes but only supports one thread per process Solaris /NT supports multiple threads 3 4 1

Threads and Processes Processes Vs Threads 5 Have a virtual address space which holds the process image Process: an address space, an execution context Protected access to processors, other processes, files, and I/O resources Context switch between processes expensive Threads of a process execute in a single address space Global variables are shared Context switch is less expensive (need only save thread state) Class threadex{ Public static void main(string arg[]){ Int x=0; My_thread t1= new my_thread(x); t1.start(); Thr_wait(); System.out.println(x) } } Class my_thread extends Thread{ My_thread(int x){ this.x = x} Public void run(){ x++;} } private int x;} 6 Threads Has an execution state (running, ready, etc.) Saves thread context 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 process all threads of a process share this when one thread alters a (non-private) memory item, all other threads (of the process) sees that a file open with one thread, is available to others 7 Single Threaded and Multithreaded Process Models Thread Control Block contains a register image, thread priority and 8 thread state information 2

Benefits of Threads vs Processes Takes less time to create a new thread than a process Less time to terminate a thread than a process Less time to switch between two threads within the same process 9 Benefits of Threads Example: a file server on a LAN It needs to handle several file 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 Example2: one thread display menu and read user input while the other thread execute user commands 10 Application benefits of threads Benefits of Threads 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 switching to another process) 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 data (chap 5) 11 12 3

Threads States/package User-Level Threads (ULT) Three key states: running, ready, blocked Termination of a process, terminates all threads within the process Thread create, thread run Thread scheduling Thread yield, specify priority, thread wait, thread sleep The kernel is not aware of the existence of threads All thread management is done by the application by using a thread library Thread switching does not require kernel mode privileges (no mode switch) Scheduling is application specific 13 14 Threads library Kernel activity for ULTs Contains code for: creating and destroying threads passing messages and data between threads scheduling thread execution saving and restoring thread contexts The kernel is not aware of thread activity but it is still managing process activity When a thread makes a system call, the whole process will be blocked but for the thread library that thread is still in the running state So thread states are independent of process states 15 16 4

Advantages and inconveniences of ULT Kernel-Level Threads (KLT) Advantages Thread switching does not involve the kernel: no mode switching Scheduling can be application specific: choose the best algorithm. ULTs can run on any OS. Only needs a thread library Inconveniences Most system calls are blocking and the kernel blocks processes. So all threads within the process will be blocked The kernel can only assign processes to processors. Two threads within the same process cannot run simultaneously on two processors All thread management is done by kernel No thread library but an API to the kernel thread facility Kernel maintains context information for the process and the threads Switching between threads requires the kernel Scheduling on a thread basis Ex: Windows NT and OS/2 17 18 Advantages and inconveniences of KLT Combined ULT/KLT Approaches Advantages the kernel can simultaneously schedule many threads of the same process on many processors blocking is done on a thread level kernel routines can be multithreaded Inconveniences thread switching within the same process involves the kernel. We have 2 mode switches per thread switch this results in a significant slow down 19 Thread creation done in the user space Bulk of scheduling and synchronization of threads done in the user space The programmer may adjust the number of KLTs May combine the best of both approaches Example is Solaris 20 5

Solaris Process includes the user s address space, stack, and process control block User-level threads (threads library) invisible to the OS are the interface for application parallelism Kernel threads the unit that can be dispatched on a processor and it s structures are maintain by the kernel Lightweight processes (LWP) each LWP supports one or more ULTs and maps to exactly one KLT each LWP is visible to the application 21 Process 2 is equivalent to a pure ULT approach Process 4 is equivalent to a pure KLT approach We can specify a different degree of parallelism (process 3 and 5) 22 Solaris: versatility Solaris: user-level thread execution We can use ULTs when logical parallelism does not need to be supported by hardware parallelism (we save mode switching) Ex: Multiple windows but only one is active at any one time If threads may block then we can specify two or more LWPs to avoid blocking the whole application 23 Transitions among these states is under the exclusive control of the application a transition can occur only when a call is made to a function of the thread library It s only when a ULT is in the active state that it is attached to a LWP (so that it will run when the kernel level thread runs) a thread may transfer to the sleeping state by invoking a synchronization primitive (chap 5) and later transfer to the runnable state when the event waited for occurs A thread may force another thread to go to the stop state... 24 6

Solaris: user-level thread states Decomposition of user-level Active state (attached to a LWP) When a ULT is Active, it is associated to a LWP and, thus, to a KLT Transitions among the LWP states is under the exclusive control of the kernel A LWP can be in the following states: running: when the KLT is executing blocked: because the KLT issued a blocking system call (but the ULT remains bound to that LWP and remains active) runnable: waiting to be dispatched to CPU 25 26 Solaris: Lightweight Process States Thread scheduling All runnable threads are on user level prioritized dispatch queue Priority can vary from 0 to infinity LWP picks the highest priority runnable thread from the dispatch queue When thread blocks at user level, then the LWP picks the next runnable thread LWP states are independent of ULT states (except for bound ULTs) 27 28 7