Operating Systems CMPSC 473 Threads September 16, 2010 - Lecture 7 Instructor: Bhuvan Urgaonkar.

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

CMPT 401 Dr. Alexandra Fedorova Lecture III: OS Support.
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.
Chapter 5 Processes and Threads Copyright © 2008.
Processes CSCI 444/544 Operating Systems Fall 2008.
Ceng Operating Systems Chapter 2.5 : Threads Process concept  Process scheduling  Interprocess communication  Deadlocks  Threads.
3.5 Interprocess Communication Many operating systems provide mechanisms for interprocess communication (IPC) –Processes must communicate with one another.
3.5 Interprocess Communication
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.
Threads CS 416: Operating Systems Design, Spring 2001 Department of Computer Science Rutgers University
Threads Chapter 4. Modern Process & Thread –Process is an infrastructure in which execution takes place  (address space + resources) –Thread is a program.
Threads math 442 es Jim Fix. Reality vs. Abstraction A computer’s OS manages a lot: multiple users many devices; hardware interrupts multiple application.
Chapter 51 Threads Chapter 5. 2 Process Characteristics  Concept of Process has two facets.  A Process is: A Unit of resource ownership:  a virtual.
CSE 451: Operating Systems Autumn 2013 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Operating Systems CSE 411 CPU Management Sept Lecture 11 Instructor: Bhuvan Urgaonkar.
1 From Processes to Threads. 2 Processes, Threads and Processors Hardware can interpret N instruction streams at once  Uniprocessor, N==1  Dual-core,
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.
Threads Many software packages are multi-threaded Web browser: one thread display images, another thread retrieves data from the network Word processor:
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Threads and Processes.
Operating Systems CMPSC 473 Processes (4) September Lecture 10 Instructor: Bhuvan Urgaonkar.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 13 Threads Read Ch 5.1.
Operating Systems CSE 411 Multi-processor Operating Systems Multi-processor Operating Systems Dec Lecture 30 Instructor: Bhuvan Urgaonkar.
Operating Systems CMPSC 473 Lecture 8: Threads September Instructor: Bhuvan Urgaonkar.
Source: Operating System Concepts by Silberschatz, Galvin and Gagne.
CS333 Intro to Operating Systems Jonathan Walpole.
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 (Pgs 153 – 174). Threads  A "Basic Unit of CPU Utilization"  A technique that assists in performing parallel computation by setting.
1 Lecture 4: Threads Advanced Operating System Fall 2010.
H.-H. S. Lee 1 ECE3055 Computer Architecture and Operating Systems Lecture 10 Process, Thread Prof. Hsien-Hsin Sean Lee School of Electrical and Computer.
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
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.
Multithreaded Programing. Outline Overview of threads Threads Multithreaded Models  Many-to-One  One-to-One  Many-to-Many Thread Libraries  Pthread.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 4: Threads.
Operating Systems CSE 411 CPU Management Sept Lecture 10 Instructor: Bhuvan Urgaonkar.
Operating Systems CMPSC 473 Processes (6) September Lecture 12 Instructor: Bhuvan Urgaonkar.
Department of Computer Science and Software Engineering
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Operating Systems CMPSC 473 Processes (3) September Lecture 9 Instructor: Bhuvan Urgaonkar.
1 Chapter 2.5 : Threads Process concept  Process concept  Process scheduling  Process scheduling  Interprocess communication  Interprocess communication.
CSC 360, Instructor: Kui Wu Thread & PThread. CSC 360, Instructor: Kui Wu Agenda 1.What is thread? 2.User vs kernel threads 3.Thread models 4.Thread issues.
Threads. Readings r Silberschatz et al : Chapter 4.
Goals for Today How do we provide multiprogramming? What are Processes? How are they related to Threads and Address Spaces? Note: Some slides and/or pictures.
Operating Systems CMPSC 473 Processes (5) September Lecture 11 Instructor: Bhuvan Urgaonkar.
Operating System Concepts
Chapter 4: Threads 羅習五. Chapter 4: Threads Motivation and Overview Multithreading Models Threading Issues Examples – Pthreads – Windows XP Threads – Linux.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Contents 1.Overview 2.Multithreading Model 3.Thread Libraries 4.Threading Issues 5.Operating-system Example 2 OS Lab Sun Suk Kim.
Processes Chapter 3. Processes in Distributed Systems Processes and threads –Introduction to threads –Distinction between threads and processes 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.
Threads Overview Benefits, User and Kernel Threads.
Processes and threads.
Operating Systems CMPSC 473
Process Management Process Concept Why only the global variables?
CS 6560: Operating Systems Design
Scheduler activations
CS399 New Beginnings Jonathan Walpole.
Chapter 2 Processes and Threads Today 2.1 Processes 2.2 Threads
Chapter 4: Multithreaded Programming
Threads & multithreading
Chapter 4: Threads.
Operating System Concepts
ICS 143 Principles of Operating Systems
Lecture 10: Threads Implementation
Threads Chapter 4.
Lecture 10: Threads Implementation
Presentation transcript:

Operating Systems CMPSC 473 Threads September 16, Lecture 7 Instructor: Bhuvan Urgaonkar

Overview of Process- related Topics How a process is born –Parent/child relationship –fork, clone, … How it leads its life –Loaded: –Executed CPU scheduling Context switching Where a process “lives”: Address space –OS maintains some info. for each process: PCB –Process = Address Space + PCB How processes request services from the OS –System calls How processes communicate Some variants of processes: threads How processes die Done Done (project 1) Done today

codedata registersstack heap The notion of a thread Roughly, a flow of execution that is a basic unit of CPU utilization –E.g., a process, a KCP thread A single-threaded process

Multi-process Applications Many applications need to do multiple activities simultaneously –E.g., Web browser Parse requested URL and find IP address from DNS server Use system calls to send request to some Web server Receive response Assemble response and display it –Can you give another example? Solution #1: Write multi-process application as follows: –forks off multiple processes, each responsible for a certain “flow of execution” Programmer’s choice/decision –Employ IPC mechanisms for these processes to communicate (coming up soon) We already know about signals, how many have used pipes? Shared memory? –Employ synchronization (ccoming up in a few lectures)

Multi-process Applications Many applications need to do multiple activities simultaneously –E.g., Web browser Parse requested URL and find IP address from DNS server Use system calls to send request to some Web server Receive response Assemble response and display it –Can you give another example? Approach #1: Write multi-process application as follows: –forks off multiple processes, each responsible for a certain “flow of execution” Programmer’s choice/decision –Employ IPC mechanisms for these processes to communicate (coming up soon) We already know about signals, how many have used pipes? Other kinds of shared memory? –Employ synchronization (coming up in a few lectures)

Approach #1: Writing a multi-process Application E.g., a Web browser codedata registersstack heap URL parsing process codedata registersstack heap codedata registersstack heap codedata registersstack heap Network sending process Network reception process Interprets response, composes media together and displays on browser screen In virtual memory

Approach #1: Writing a multi-process Application E.g., a Web browser Potentially, lot of redundancy in code, data, and heap segments! –Virtual memory wastage => More contention for precious RAM => More waiting for slow swap device => Reduction in computer’s throughput Also, TLB and cache contention between processes part of the same application codedata registersstack heap URL parsing process codedata registersstack heap codedata registersstack heap codedata registersstack heap Network sending process Network reception process Interprets response, composes media together and displays on browser screen In virtual memory

Approach #2: Share code, data, heap! E.g., a Web browser Share code, data, heap via shared memory mechanisms (coming up) –Make them part of the same address space Or let kernel or a user-library handle sharing of these parts of the address spaces and let the programmer deal only with synchronization issues –Kernel vs. User threads URL parsing processNetwork sending process Network reception process Interprets response, composes media together and displays on browser screen In virtual memory code data registersstack heap registersstackregistersstackregistersstack threads

(Old) Process Address Space

(New) Address Space with Threads All threads in a process share the same address space

Implementing Threads Given what we know about processes, implementing threads is “easy” Idea: Break the PCB into two pieces: –Thread-specific stuff: Processor state –Process-specific state: Address space and OS resources (e.g., open files)

Thread Control Block (TCB) TCB contains info on a single thread –Just processor state and pointer to corresponding PCB PCB contains info on the containing process –Address space and OS resources, but NO processor state!

Thread Control Block (TCB) TCBs are smaller and cheaper than PCBs –Linux TCB (thread_struct) has 24 fields –Linux PCB (task_struct) has 106 fields

Context Switching TCB is now the unit of a context switch –Ready queue, wait queues, etc. now contain pointers to TCBs –Context switch causes CPU state to be copied to/from the TCB Context switch between two threads of the same process –No need to change address space No TLB flush Context switch between two threads of different processes –Must change address space, sometimes invalidating cache –This will become relevant when we talk about virtual memory

Prep. for Project 2 Learn pthreads calls –Multi-threaded server and clients – –Use Solaris or Linux –Thread management pthread_create, pthread_exit –Threads synchronization Choose one of the following –pthread_join, pthread_detach –pthread_mutex_init, pthread_mutex_lock, pthread_mutex_unlock, pthread_mutex_destroy »We will study the “mutex” problem closely starting next week