Threads Many software packages are multi-threaded Web browser: one thread display images, another thread retrieves data from the network Word processor:

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

Process management Information maintained by OS for process management  process context  process control block OS virtualization of CPU for each process.
Chap 4 Multithreaded Programming. Thread A thread is a basic unit of CPU utilization It comprises a thread ID, a program counter, a register set and a.
Concurrency: Threads, Address Spaces, and Processes Sarah Diesburg Operating Systems COP 4610.
Why Concurrency? Allows multiple applications to run at the same time  Analogy: juggling.
1/27/2010CSCI 315 Operating Systems Design1 Processes Notice: The slides for this lecture have been largely based on those accompanying an earlier version.
CSCE 351: Operating System Kernels
OS Spring’03 Introduction Operating Systems Spring 2003.
1/23/2008CSCI 315 Operating Systems Design1 Processes Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
Process Concept An operating system executes a variety of programs
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Operating Systems (CSCI2413) Lecture 3 Processes phones off (please)
Using Two Queues. Using Multiple Queues Suspended Processes Processor is faster than I/O so all processes could be waiting for I/O Processor is faster.
Phones OFF Please Processes Parminder Singh Kang Home:
Chapter 51 Threads Chapter 5. 2 Process Characteristics  Concept of Process has two facets.  A Process is: A Unit of resource ownership:  a virtual.
Operating Systems CSE 411 CPU Management Sept Lecture 11 Instructor: Bhuvan Urgaonkar.
9/13/20151 Threads ICS 240: Operating Systems –William Albritton Information and Computer Sciences Department at Leeward Community College –Original slides.
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.
Implementing Processes and Process Management Brian Bershad.
Concurrency: Threads, Address Spaces, and Processes Andy Wang Operating Systems COP 4610 / CGS 5765.
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
Processes and Threads CS550 Operating Systems. Processes and Threads These exist only at execution time They have fast state changes -> in memory and.
1 RTOS Design Some of the content of this set of slides is taken from the documentation existing on the FreeRTOS website
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Thread Scheduling.
CSC139 Operating Systems Lecture 4 Thread Dispatching Adapted from Prof. John Kubiatowicz's lecture notes for CS162
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 13 Threads Read Ch 5.1.
Process by Dr. Amin Danial Asham. References Operating System Concepts ABRAHAM SILBERSCHATZ, PETER BAER GALVIN, and GREG GAGNE.
Multiprogramming. Readings r Silberschatz, Galvin, Gagne, “Operating System Concepts”, 8 th edition: Chapter 3.1, 3.2.
CS 162 Discussion Section Week 2. Who am I? Haoyuan (HY) Li Office Hours: 1pm-3pm
CS 162 Discussion Section Week 2. Who am I? Wesley Chow Office Hours: 12pm-2pm 411 Soda Does Monday 1-3 work for everyone?
Chapter 2 Processes and Threads Introduction 2.2 Processes A Process is the execution of a Program More specifically… – A process is a program.
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.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Process-Concept.
Concurrency & Context Switching Process Control Block What's in it and why? How is it used? Who sees it? 5 State Process Model State Labels. Causes of.
Operating Systems CSE 411 CPU Management Sept Lecture 10 Instructor: Bhuvan Urgaonkar.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Processes & Threads Introduction to Operating Systems: Module 5.
1 Process Description and Control Chapter 3. 2 Process A program in execution An instance of a program running on a computer The entity that can be assigned.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 4: Processes Process Concept Process Scheduling Types of shedulars Process.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Threads by Dr. Amin Danial Asham. References Operating System Concepts ABRAHAM SILBERSCHATZ, PETER BAER GALVIN, and GREG GAGNE.
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,
Multiprogramming. Readings r Chapter 2.1 of the textbook.
Processes and threads.
Process concept.
CSCS 511 Operating Systems Ch3, 4 (Part B) Further Understanding Threads Dr. Frank Li Skipped sections 3.5 & 3.6 
Scheduler activations
Lecture Topics: 11/1 Processes Process Management
Intro to Processes CSSE 332 Operating Systems
Threads & multithreading
Chapter 4: Threads.
Operating System Concepts
Process Virtualization. Process Process is a program that has initiated its execution. A program is a passive entity; whereas a process is an active entity.
Operating Systems (CS 340 D)
Concurrency: Threads, Address Spaces, and Processes
CSCI 511 Operating Systems Ch3, 4 (Part B) Further Understanding Threads Dr. Frank Li Skipped sections 3.5 & 3.6 
Concurrency: Threads, Address Spaces, and Processes
PROCESS MANAGEMENT Information maintained by OS for process management
Lecture Topics: 11/1 General Operating System Concepts Processes
Processes Hank Levy 1.
Multithreaded Programming
Processes and Process Management
EE 472 – Embedded Systems Dr. Shwetak Patel.
Operating Systems (CS 340 D)
Processes Hank Levy 1.
Concurrency: Threads, Address Spaces, and Processes
Chapter 3: Process Management
Presentation transcript:

Threads Many software packages are multi-threaded Web browser: one thread display images, another thread retrieves data from the network Word processor: threads for displaying graphics, reading keystrokes from the user, performing spelling and grammar checking in the background A thread is sometimes called a lightweight process It is comprised over a thread ID, program counter, a register set and a stack It shares with other threads belonging to the same process its code section, data section and other OS resources (e.g., open files) A process that has multiples threads can do more than one task at a time

Benefits Responsiveness One part of a program can continue running even if another part is blocked Resource Sharing Threads of the same process share the same memory space and resources Economy Much less time consuming to create and manage threads than processes

Single and Multithreaded Processes

Lifecycle of a Thread (or Process) As a thread executes, it changes state: new: The thread is being created ready: The thread is waiting to run running: Instructions are being executed waiting: Thread waiting for some event to occur terminated: The thread has finished execution Active threads are represented by their TCBs TCBs organized into queues based on their state

Java Thread States

Ready Queue And Various I/O Device Queues Thread not running  TCB is in some scheduler queue Separate queue for each device/signal/condition Each queue can have a different scheduler policy Other State TCB 9 Link Registers Other State TCB 6 Link Registers Other State TCB 16 Link Registers Other State TCB 8 Link Registers Other State TCB 2 Link Registers Other State TCB 3 Link Registers Head Tail Head Tail Head Tail Head Tail Head Tail Ready Queue Tape Unit 0 Disk Unit 0 Disk Unit 2 Ether Netwk 0

Dispatch Loop Conceptually, the dispatching loop of the operating system looks as follows: Loop { RunThread(); ChooseNextThread(); SaveStateOfCPU(curTCB); LoadStateOfCPU(newTCB); }

Running a thread Consider first portion: RunThread() How do I run a thread? Load its state (registers, PC, stack pointer) into CPU Load environment (virtual memory space, etc) Jump to the PC How does the dispatcher get control back? Internal events: thread returns control voluntarily External events: thread gets preempted

Internal Events Blocking on I/O The act of requesting I/O implicitly yields the CPU Waiting on a “signal” from other thread Thread asks to wait and thus yields the CPU Thread executes a yield() Thread volunteers to give up CPU computePI() { while(TRUE) { ComputeNextDigit(); yield(); } }

Choosing a Thread to Run How does Dispatcher decide what to run? Zero ready threads – dispatcher loops Alternative is to create an “idle thread” Can put machine into low-power mode Exactly one ready thread – easy More than one ready thread: use scheduling priorities Possible priorities: LIFO (last in, first out): put ready threads on front of list, remove from front Pick one at random FIFO (first in, first out): Put ready threads on back of list, pull them from front This is fair and is what Nachos does Priority queue: keep ready list sorted by TCB priority field

Summary The state of a thread is contained in the TCB Registers, PC, stack pointer States: New, Ready, Running, Waiting, or Terminated Multithreading provides simple illusion of multiple CPUs Switch registers and stack to dispatch new thread Provide mechanism to ensure dispatcher regains control Many scheduling options Decision of which thread to run