CSE120 Principles of Operating Systems. Prof Yuanyuan (YY) Zhou Lecture 4: Threads

Size: px
Start display at page:

Download "CSE120 Principles of Operating Systems. Prof Yuanyuan (YY) Zhou Lecture 4: Threads"

Transcription

1 CSE120 Principes of Operating Systems Prof Yuanyuan (YY) Zhou Lecture 4: Threads

2 Announcement Project 0 Due Project 1 out Homework 1 due on Thursday Submit it to Gradescope onine 2

3 Processes Reca that a process incudes many things An address space (defining a the code and data pages) OS resources (e.g., open fies) and accounting information Execution state (PC, SP, regs, etc.) Creating a new process is costy because of a of the data structures that must be aocated and initiaized Reca struct proc in Soaris Communicating between processes is costy because most communication goes through the OS Overhead of system cas and copying data 3

4 Parae Programs To execute these programs we need to Create severa processes that execute in parae Have the OS schedue these processes in parae (ogicay or physicay) This situation is very inefficient Space: PCB, page tabes, etc. Time: create data structures, fork and copy addr space, etc. Soution: possibe to have cooperating processes? 4

5 Rethinking Processes Key idea: Why don t we separate the concept of a process from its execution state? Process: address space, privieges, resources, etc. Execution state: PC, SP, registers Exec state aso caed thread of contro, or thread 5

6 Threads Thread vs Process A thread defines a sequentia execution stream within a process (PC, SP, registers) A process defines the address space and genera process attributes (everything but threads of execution) A thread is bound to a singe process A process, however, can have mutipe threads Threads become the unit of scheduing Processes are now the containers in which threads execute 6

7 Threads: Lightweight Processes A sequentia execution stream within a process Environment (resource) execution 7 (a) Three processes each with one thread (b) One process with three threads

8 The Thread Mode 8 Shared information Processor info: parent process, time, etc Memory: goba data, heap, page tabe, and stats, etc I/O and fie: communication ports, directories and fie descriptors, etc Private state State (ready, running and bocked) Registers Program counter Execution stack Why? Each thread execute separatey

9 Threads in a Process Stack (T1) Thread 1 Thread 2 Stack (T2) Stack (T3) Thread 3 9 PC (T2) Heap Static Data Code PC (T3) PC (T1)

10 Anaogy Process: 3 projects for different casses (CSE120, CSE140, CSE110) Each one has different text book, different web pages, different TAs/Instructors Threads: 3 activities in CSE120 (Homework, Lectures, Projects) Share the same concepts (textbook) Share TA/Tutors A of them are going on in parae (within one quarter) Each has their own things, too 10 10/7/18

11 A 2-min Expainer Video DYO1K78 11

12 Threads: Concurrent Servers Using fork() to create new processes to hande requests in parae is overki for such a simpe task Reca our forking Web server: 12 whie (1) { } int sock = accept(); if ((chid_pid = fork()) == 0) { Hande cient request Cose socket and exit } ese { Cose socket }

13 Threads: Concurrent Servers Instead, we can create a new thread for each request web_server() { } whie (1) { } int sock = accept(); thread_fork(hande_request, sock); Difference from fork()? 13 hande_request(int sock) { Process request cose(sock); }

14 Thread Usage: Web Server 14

15 Thread Usage: word processor A thread can wait for I/O, whie the other threads can sti running. What if it is singe-threaded? 15

16 Windows Thread Lists from Performance Monitor 16

17 Windows Performance Anayzer 17

18 Mac OS Activity Monitor 18 10/7/18 CSE120 - Operating Systems, Yuanyuan Zhou

19 Thread Information on Linux Process information: Read /proc/[your PID]/stat fie Thread information (2.6 kerne): Read /proc/[your PID]/task/[thread ID]/stat 19

20 Kerne-managed Threads We have taken the execution aspect of a process and separated it out into threads To make concurrency cheaper As such, the OS now manages threads and processes A thread operations are impemented in the kerne The OS schedues a of the threads in the system OS-managed threads are caed kerne-eve threads or Kerne managed threads or ightweight processes NT: threads Soaris: ightweight processes (LWP) POSIX Threads (pthreads): PTHREAD_SCOPE_SYSTEM 20

21 Kerne-managed Thread Limitations Kerne-managed threads make concurrency much cheaper than processes Much ess state to aocate and initiaize However, for fine-grained concurrency, kernemanaged threads sti suffer from too much overhead Thread operations sti require system cas Ideay, want thread operations to be as fast as a procedure ca Kerne-eve threads have to be genera to support the needs of a programmers, anguages, runtimes, etc. For more fine-grained concurrency, need even cheaper threads 21

22 User-Leve-Managed Threads 22 To make threads cheap and fast, they need to be impemented at user eve Kerne-eve managed threads are managed by the OS User-eve managed threads are managed entirey by the runtime system (user-eve ibrary) User-eve-managed threads are sma and fast A thread is simpy represented by a PC, registers, stack, and sma thread contro bock (TCB) Creating a new thread, switching between threads, and synchronizing threads are done via procedure ca No kerne invovement User-eve managed thread operations 100x faster than kerne managed threads pthreads: PTHREAD_SCOPE_PROCESS

23 User eve threads Kerne eve Managed threads User eve Managed threads 23

24 Sma and Fast Nachos thread contro bock cass Thread { int *stack; int *stacktop; int machinestate[machinestatesize]; ThreadStatus status; char *name; <Methods> }; 24

25 User Leve Managed Thread Limitations But, user-eve managed threads are not a perfect soution As with everything ese, they are a tradeoff User-eve managed threads are invisibe to the OS They are not we integrated with the OS As a resut, the OS can make poor decisions Scheduing a process with ide threads Bocking a process whose thread initiated an I/O, even though the process has other threads that can execute Unscheduing a process with a thread hoding a ock Soving this requires communication between the kerne and the user-eve thread manager 25

26 Tradeoffs between the two Kerne-eve managed threads Integrated with OS (informed scheduing) Sow to create, manipuate, synchronize User-eve managed threads Fast to create, manipuate, synchronize Not integrated with OS (uninformed scheduing) Understanding the differences between kerne and user-eve managed threads is important For programming (correctness, performance) 26

27 Kerne and User Threads Or use both kerne and user-eve threads Can associate a user-eve thread with a kerne-eve thread Or, mutipex user-eve threads on top of kerne-eve threads Java Virtua Machine (JVM) (aso pthreads) Java threads are user-eve threads On oder Unix, ony one kerne thread per process Mutipex a Java threads on this one kerne thread On NT, modern Unix Can mutipex Java threads on mutipe kerne threads Can have more Java threads than kerne threads 27

28 Impementing Threads Impementing threads has a number of issues Interface Context switch Preemptive vs. non-preemptive Scheduing Synchronization (next ecture) Focus on user-eve managed threads Kerne-eve managed threads are simiar to origina process management and impementation in the OS What you wi be deaing with in Nachos Not ony wi you be using threads in Nachos, you wi be impementing more thread functionaity 28

29 Sampe Thread Interface 29 thread_fork(procedure_t) Create a new thread of contro Aso thread_create(), thread_setstate() thread_stop() Stop the caing thread; aso thread_bock thread_start(thread_t) Start the given thread thread_yied() Vountariy give up the processor thread_exit() Terminate the caing thread; aso thread_destroy Thread_join(t) or t.join() causes the current thread to pause execution unti t's thread terminates

30 Thread Scheduing The thread scheduer determines when a thread runs It uses queues to keep track of what threads are doing Just ike the OS and processes But it is impemented at user-eve in a ibrary Run queue: Threads currenty running (usuay one) Ready queue: Threads ready to run Are there wait queues? How woud you impement thread_seep(time)? 30

31 Non-Preemptive Scheduing Threads vountariy give up the CPU with thread_yied Ping Thread Pong Thread whie (1) { printf( ping\n ); thread_yied(); } whie (1) { printf( pong\n ); thread_yied(); } 31 What is the output of running these two threads?

32 thread_yied() Wait a second. How does thread_yied() work? The semantics of thread_yied are that it gives up the CPU to another thread In other words, it context switches to another thread So what does it mean for thread_yied to return? It means that another thread caed thread_yied! Execution trace of ping/pong printf( ping\n ); thread_yied(); printf( pong\n ); thread_yied(); 32

33 Impementing thread_yied() thread_yied() { } thread_t od_thread = current_thread; current_thread = get_next_thread(); append_to_queue(ready_queue, od_thread); context_switch(od_thread, current_thread); return; As od thread As new thread The magic step is invoking context_switch() Why do we need to ca append_to_queue()? 33

34 Thread Context Switch The context switch routine does a of the magic Saves context of the currenty running thread (od_thread) Push a machine state onto its stack (not its TCB) Restores context of the next thread Pop a machine state from the next thread s stack The next thread becomes the current thread Return to the NEW thread This is a done in assemby anguage It works at the eve of the procedure caing convention, so it cannot be impemented using procedure cas See code/threads/switch.s in Nachos 34

35 Preemptive Scheduing Non-preemptive threads have to vountariy give up CPU A ong-running thread wi take over the CPU Ony vountary cas to thread_yied(), thread_stop(), or thread_exit() causes a context switch Preemptive scheduing causes an invountary context switch Need to regain contro of processor asynchronousy How? Use timer/aarm interrupt 35

36 Bocking Vs. non-bocking System Cas Bocking system ca Usuay I/O reated: read(), fread(), getc(), write() Doesn t return unti the ca competes The process/thread is switched to bocked state When the I/O competes, the process/thread becomes ready Simpe Rea ife exampe: attending a ecture Using non-bocking system ca for I/O Asynchronous I/O Compicated The ca returns once the I/O is initiated, and the caer continue Once the I/O competes, an interrupt is deivered to the caer Rea ife exampe: appy for job 36

37 Threads Summary 37 The operating system as a arge mutithreaded program Each process executes as a thread within the OS Mutithreading is aso very usefu for appications Efficient mutithreading requires fast primitives Processes are too heavyweight Soution is to separate threads from processes Kerne-eve managed threads much better, but sti significant overhead User-eve managed threads even better, but not we integrated with OS Now, how do we get our threads to correcty cooperate with each other? Synchronization

CSE 120 Principles of Operating Systems

CSE 120 Principles of Operating Systems CSE 120 Principles of Operating Systems Spring 2009 Lecture 4: Threads Geoffrey M. Voelker Announcements Homework #1 due now Project 0 due tonight Project 1 out April 9, 2009 CSE 120 Lecture 4 Threads

More information

CSE 120 Principles of Operating Systems

CSE 120 Principles of Operating Systems CSE 120 Principles of Operating Systems Fall 2015 Lecture 4: Threads Geoffrey M. Voelker Announcements Project 0 due Project 1 out October 6, 2015 CSE 120 Lecture 4 Threads 2 Processes Recall that a process

More information

Lecture 4: Threads; weaving control flow

Lecture 4: Threads; weaving control flow Lecture 4: Threads; weaving control flow CSE 120: Principles of Operating Systems Alex C. Snoeren HW 1 Due NOW Announcements Homework #1 due now Project 0 due tonight Project groups Please send project

More information

CSE 120 Principles of Operating Systems

CSE 120 Principles of Operating Systems CSE 120 Principles of Operating Systems Fall 2000 Lecture 5: Threads Geoffrey M. Voelker Processes Recall that a process includes many things An address space (defining all the code and data pages) OS

More information

CS 153 Design of Operating Systems Winter 2016

CS 153 Design of Operating Systems Winter 2016 CS 153 Design of Operating Systems Winter 2016 Lecture 6: Threads Recap: Process Components Per- Process State Per- Thread State A process is named using its process ID (PID) A process contains all of

More information

CSE 153 Design of Operating Systems Fall 2018

CSE 153 Design of Operating Systems Fall 2018 CSE 153 Design of Operating Systems Fall 2018 Lecture 5: Threads/Synchronization Implementing threads l Kernel Level Threads l u u All thread operations are implemented in the kernel The OS schedules all

More information

CS 318 Principles of Operating Systems

CS 318 Principles of Operating Systems CS 318 Principles of Operating Systems Fall 2017 Lecture 5: Thread Ryan Huang Administrivia HW1 solution released on Piazza resources Lab 0 grading - In progress - Cheating policy Lab 1 review session

More information

CS 318 Principles of Operating Systems

CS 318 Principles of Operating Systems CS 318 Principles of Operating Systems Fall 2018 Lecture 5: Thread Ryan Huang Slides adapted from Geoff Voelker s and David Mazières lectures Administrivia Lab 0 grading in progress Lab 1 review session

More information

CS 153 Design of Operating Systems Spring 18

CS 153 Design of Operating Systems Spring 18 CS 153 Design of Operating Systems Spring 18 Lectre 8: Threads Instrctor: Chengy Song Slide contribtions from Nael Ab-Ghazaleh, Harsha Madhyvasta and Zhiyn Qian Processes P1 P2 Recall that Bt OS A process

More information

CSE120 Principles of Operating Systems. Prof Yuanyuan (YY) Zhou Midterm Review

CSE120 Principles of Operating Systems. Prof Yuanyuan (YY) Zhou Midterm Review CSE120 Principes of Operating Systems Prof Yuanyuan (YY) Zhou Midterm Review Overview The midterm Architectura support for OSes OS modues, interfaces, and structures Processes Threads Synchronization Scheduing

More information

CSE 153 Design of Operating Systems Fall 2018

CSE 153 Design of Operating Systems Fall 2018 CSE 153 Design of Operating Systems Fall 2018 Lecture 4: Processes (2) Threads Process Creation: Unix In Unix, processes are created using fork() int fork() fork() Creates and initializes a new PCB Creates

More information

CSE120 Principles of Operating Systems. Prof Yuanyuan (YY) Zhou Scheduling

CSE120 Principles of Operating Systems. Prof Yuanyuan (YY) Zhou Scheduling CSE120 Principes of Operating Systems Prof Yuanyuan (YY) Zhou Scheduing Announcement Homework 2 due on October 25th Project 1 due on October 26th 2 CSE 120 Scheduing and Deadock Scheduing Overview In discussing

More information

Lecture 5: Synchronization w/locks

Lecture 5: Synchronization w/locks Lecture 5: Synchronization w/locks CSE 120: Principles of Operating Systems Alex C. Snoeren Lab 1 Due 10/19 Threads Are Made to Share Global variables and static objects are shared Stored in the static

More information

CSE120 Principles of Operating Systems. Prof Yuanyuan (YY) Zhou Advanced Memory Management

CSE120 Principles of Operating Systems. Prof Yuanyuan (YY) Zhou Advanced Memory Management CSE120 Principes of Operating Systems Prof Yuanyuan (YY) Zhou Advanced Memory Management Advanced Functionaity Now we re going to ook at some advanced functionaity that the OS can provide appications using

More information

Threads Implementation. Jo, Heeseung

Threads Implementation. Jo, Heeseung Threads Implementation Jo, Heeseung Today's Topics How to implement threads? User-level threads Kernel-level threads Threading models 2 Kernel/User-level Threads Who is responsible for creating/managing

More information

CSE120 Principles of Operating Systems. Architecture Support for OS

CSE120 Principles of Operating Systems. Architecture Support for OS CSE120 Principes of Operating Systems Architecture Support for OS Why are you sti here? You shoud run away from my CSE120! 2 CSE 120 Architectura Support Announcement Have you visited the web page? http://cseweb.ucsd.edu/casses/fa18/cse120-a/

More information

Threads Implementation. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Threads Implementation. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Threads Implementation Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Today s Topics How to implement threads? User-level threads Kernel-level

More information

CPSC 341 OS & Networks. Threads. Dr. Yingwu Zhu

CPSC 341 OS & Networks. Threads. Dr. Yingwu Zhu CPSC 341 OS & Networks Threads Dr. Yingwu Zhu Processes Recall that a process includes many things An address space (defining all the code and data pages) OS resources (e.g., open files) and accounting

More information

Threads. Raju Pandey Department of Computer Sciences University of California, Davis Spring 2011

Threads. Raju Pandey Department of Computer Sciences University of California, Davis Spring 2011 Threads Raju Pandey Department of Computer Sciences University of California, Davis Spring 2011 Threads Effectiveness of parallel computing depends on the performance of the primitives used to express

More information

MCSE Training Guide: Windows Architecture and Memory

MCSE Training Guide: Windows Architecture and Memory MCSE Training Guide: Windows 95 -- Ch 2 -- Architecture and Memory Page 1 of 13 MCSE Training Guide: Windows 95-2 - Architecture and Memory This chapter wi hep you prepare for the exam by covering the

More information

Questions answered in this lecture: CS 537 Lecture 19 Threads and Cooperation. What s in a process? Organizing a Process

Questions answered in this lecture: CS 537 Lecture 19 Threads and Cooperation. What s in a process? Organizing a Process Questions answered in this lecture: CS 537 Lecture 19 Threads and Cooperation Why are threads useful? How does one use POSIX pthreads? Michael Swift 1 2 What s in a process? Organizing a Process A process

More information

Maru: Hardware-Assisted Secure Cloud Computing

Maru: Hardware-Assisted Secure Cloud Computing Maru: Hardware-Assisted Secure Coud Computing Peter Pietzuch prp@imperia.ac.uk Large-Scae Distributed Systems Group Department of Computing, Imperia Coege London Peter R. Pietzuch http://sds.doc.ic.ac.uk

More information

Threads. Computer Systems. 5/12/2009 cse threads Perkins, DW Johnson and University of Washington 1

Threads. Computer Systems.   5/12/2009 cse threads Perkins, DW Johnson and University of Washington 1 Threads CSE 410, Spring 2009 Computer Systems http://www.cs.washington.edu/410 5/12/2009 cse410-20-threads 2006-09 Perkins, DW Johnson and University of Washington 1 Reading and References Reading» Read

More information

Threads. CS-3013 Operating Systems Hugh C. Lauer. CS-3013, C-Term 2012 Threads 1

Threads. CS-3013 Operating Systems Hugh C. Lauer. CS-3013, C-Term 2012 Threads 1 Threads CS-3013 Operating Systems Hugh C. Lauer (Slides include materials from Slides include materials from Modern Operating Systems, 3 rd ed., by Andrew Tanenbaum and from Operating System Concepts,

More information

As Michi Henning and Steve Vinoski showed 1, calling a remote

As Michi Henning and Steve Vinoski showed 1, calling a remote Reducing CORBA Ca Latency by Caching and Prefetching Bernd Brügge and Christoph Vismeier Technische Universität München Method ca atency is a major probem in approaches based on object-oriented middeware

More information

CSE120 Principles of Operating Systems. Prof Yuanyuan (YY) Zhou Synchronization: Semaphore

CSE120 Principles of Operating Systems. Prof Yuanyuan (YY) Zhou Synchronization: Semaphore CSE120 Principes of Operating Systems Prof Yuanyuan (YY) Zhou Synchronization: Synchronization Needs Two synchronization needs Mutua excusion Whenever mutipe threads access a shared data, you need to worry

More information

Notes. CS 537 Lecture 5 Threads and Cooperation. Questions answered in this lecture: What s in a process?

Notes. CS 537 Lecture 5 Threads and Cooperation. Questions answered in this lecture: What s in a process? Notes CS 537 Lecture 5 Threads and Cooperation Michael Swift OS news MS lost antitrust in EU: harder to integrate features Quiz tomorrow on material from chapters 2 and 3 in the book Hardware support for

More information

Processes & Threads. Process Management. Managing Concurrency in Computer Systems. The Process. What s in a Process?

Processes & Threads. Process Management. Managing Concurrency in Computer Systems. The Process. What s in a Process? Process Management Processes & Threads Managing Concurrency in Computer Systems Process management deals with several issues: what are the units of execution how are those units of execution represented

More information

Yi Shi Fall 2017 Xi an Jiaotong University

Yi Shi Fall 2017 Xi an Jiaotong University Threads Yi Shi Fall 2017 Xi an Jiaotong University Goals for Today Case for Threads Thread details Case for Parallelism main() read_data() for(all data) compute(); write_data(); endfor main() read_data()

More information

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

Page 1. Analogy: Problems: Operating Systems Lecture 7. Operating Systems Lecture 7 Os-slide#1 /*Sequential Producer & Consumer*/ int i=0; repeat forever Gather material for item i; Produce item i; Use item i; Discard item i; I=I+1; end repeat Analogy: Manufacturing and distribution Print

More information

Processes and Threads

Processes and Threads TDDI04 Concurrent Programming, Operating Systems, and Real-time Operating Systems Processes and Threads [SGG7] Chapters 3 and 4 Copyright Notice: The lecture notes are mainly based on Silberschatz s, Galvin

More information

Bridge Talk Release Notes for Meeting Exchange 5.0

Bridge Talk Release Notes for Meeting Exchange 5.0 Bridge Tak Reease Notes for Meeting Exchange 5.0 This document ists new product features, issues resoved since the previous reease, and current operationa issues. New Features This section provides a brief

More information

THREADS. Jo, Heeseung

THREADS. Jo, Heeseung THREADS Jo, Heeseung TODAY'S TOPICS Why threads? Threading issues 2 PROCESSES Heavy-weight A process includes many things: - An address space (all the code and data pages) - OS resources (e.g., open files)

More information

What s in a process?

What s in a process? CSE 451: Operating Systems Winter 2015 Module 5 Threads Mark Zbikowski mzbik@cs.washington.edu Allen Center 476 2013 Gribble, Lazowska, Levy, Zahorjan What s in a process? A process consists of (at least):

More information

An Introduction to Design Patterns

An Introduction to Design Patterns An Introduction to Design Patterns 1 Definitions A pattern is a recurring soution to a standard probem, in a context. Christopher Aexander, a professor of architecture Why woud what a prof of architecture

More information

Computer Systems Laboratory Sungkyunkwan University

Computer Systems Laboratory Sungkyunkwan University Threads Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Today s Topics Why threads? Threading issues 2 Processes Heavy-weight A process includes

More information

Operating Systems. Lecture 4. Nachos Appetizer

Operating Systems. Lecture 4. Nachos Appetizer CMSC 321: Operating Systems Lecture 4 Processes & Threads; Nachos Appetizer Before Threads Recall that a process consists of: program(s) data stack PCB all stored in the process image Process (context)

More information

file://j:\macmillancomputerpublishing\chapters\in073.html 3/22/01

file://j:\macmillancomputerpublishing\chapters\in073.html 3/22/01 Page 1 of 15 Chapter 9 Chapter 9: Deveoping the Logica Data Mode The information requirements and business rues provide the information to produce the entities, attributes, and reationships in ogica mode.

More information

CPSC 341 OS & Networks. Processes. Dr. Yingwu Zhu

CPSC 341 OS & Networks. Processes. Dr. Yingwu Zhu CPSC 341 OS & Networks Processes Dr. Yingwu Zhu Process Concept Process a program in execution What is not a process? -- program on a disk A process is an active object, but a program is just a file It

More information

Threads. What is a thread? Motivation. Single and Multithreaded Processes. Benefits

Threads. What is a thread? Motivation. Single and Multithreaded Processes. Benefits CS307 What is a thread? Threads A thread is a basic unit of CPU utilization contains a thread ID, a program counter, a register set, and a stack shares with other threads belonging to the same process

More information

Outline. Parallel Numerical Algorithms. Forward Substitution. Triangular Matrices. Solving Triangular Systems. Back Substitution. Parallel Algorithm

Outline. Parallel Numerical Algorithms. Forward Substitution. Triangular Matrices. Solving Triangular Systems. Back Substitution. Parallel Algorithm Outine Parae Numerica Agorithms Chapter 8 Prof. Michae T. Heath Department of Computer Science University of Iinois at Urbana-Champaign CS 554 / CSE 512 1 2 3 4 Trianguar Matrices Michae T. Heath Parae

More information

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

Motivation. Threads. Multithreaded Server Architecture. Thread of execution. Chapter 4 Motivation Threads Chapter 4 Most modern applications are multithreaded Threads run within application Multiple tasks with the application can be implemented by separate Update display Fetch data Spell

More information

10/10/ Gribble, Lazowska, Levy, Zahorjan 2. 10/10/ Gribble, Lazowska, Levy, Zahorjan 4

10/10/ Gribble, Lazowska, Levy, Zahorjan 2. 10/10/ Gribble, Lazowska, Levy, Zahorjan 4 What s in a process? CSE 451: Operating Systems Autumn 2010 Module 5 Threads Ed Lazowska lazowska@cs.washington.edu Allen Center 570 A process consists of (at least): An, containing the code (instructions)

More information

Concurrent programming: From theory to practice. Concurrent Algorithms 2016 Tudor David

Concurrent programming: From theory to practice. Concurrent Algorithms 2016 Tudor David oncurrent programming: From theory to practice oncurrent Agorithms 2016 Tudor David From theory to practice Theoretica (design) Practica (design) Practica (impementation) 2 From theory to practice Theoretica

More information

Multithreaded Programming

Multithreaded Programming Multithreaded Programming The slides do not contain all the information and cannot be treated as a study material for Operating System. Please refer the text book for exams. September 4, 2014 Topics Overview

More information

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

Threads. Still Chapter 2 (Based on Silberchatz s text and Nachos Roadmap.) 3/9/2003 B.Ramamurthy 1 Threads Still Chapter 2 (Based on Silberchatz s text and Nachos Roadmap.) 3/9/2003 B.Ramamurthy 1 Single and Multithreaded Processes Thread specific Data (TSD) Code 3/9/2003 B.Ramamurthy 2 User Threads

More information

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song CSCE 313 Introduction to Computer Systems Instructor: Dezhen Song Programs, Processes, and Threads Programs and Processes Threads Programs, Processes, and Threads Programs and Processes Threads Processes

More information

Lecture 2 Process Management

Lecture 2 Process Management Lecture 2 Process Management Process Concept An operating system executes a variety of programs: Batch system jobs Time-shared systems user programs or tasks The terms job and process may be interchangeable

More information

CSCE 313: Intro to Computer Systems

CSCE 313: Intro to Computer Systems CSCE 313 Introduction to Computer Systems Instructor: Dr. Guofei Gu http://courses.cse.tamu.edu/guofei/csce313/ Programs, Processes, and Threads Programs and Processes Threads 1 Programs, Processes, and

More information

CS 450 Operating System Week 4 Lecture Notes

CS 450 Operating System Week 4 Lecture Notes CS 450 Operating System Week 4 Lecture Notes Reading: Operating System Concepts (7 th Edition) - Silberschatz, Galvin, Gagne Chapter 5 - Pages 129 147 Objectives: 1. Explain the main Objective of Threads

More information

OPERATING SYSTEM. Chapter 4: Threads

OPERATING SYSTEM. Chapter 4: Threads OPERATING SYSTEM Chapter 4: Threads Chapter 4: Threads Overview Multicore Programming Multithreading Models Thread Libraries Implicit Threading Threading Issues Operating System Examples Objectives To

More information

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Hardware Components Illustrated

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Hardware Components Illustrated Intro to Programming & C++ Unit 1 Sections 1.1-3 and 2.1-10, 2.12-13, 2.15-17 CS 1428 Fa 2017 Ji Seaman 1.1 Why Program? Computer programmabe machine designed to foow instructions Program instructions

More information

Chapter 4: Threads. Overview Multithreading Models Thread Libraries Threading Issues Operating System Examples Windows XP Threads Linux Threads

Chapter 4: Threads. Overview Multithreading Models Thread Libraries Threading Issues Operating System Examples Windows XP Threads Linux Threads Chapter 4: Threads Overview Multithreading Models Thread Libraries Threading Issues Operating System Examples Windows XP Threads Linux Threads Chapter 4: Threads Objectives To introduce the notion of a

More information

Chapter 4: Multi-Threaded Programming

Chapter 4: Multi-Threaded Programming Chapter 4: Multi-Threaded Programming Chapter 4: Threads 4.1 Overview 4.2 Multicore Programming 4.3 Multithreading Models 4.4 Thread Libraries Pthreads Win32 Threads Java Threads 4.5 Implicit Threading

More information

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

I.-C. Lin, Assistant Professor. Textbook: Operating System Concepts 8ed CHAPTER 4: MULTITHREADED PROGRAMMING I.-C. Lin, Assistant Professor. Textbook: Operating System Concepts 8ed CHAPTER 4: MULTITHREADED PROGRAMMING Chapter 4: Multithreaded Programming Overview Multithreading Models Thread Libraries Threading

More information

Chapter 4: Multithreaded Programming

Chapter 4: Multithreaded Programming Chapter 4: Multithreaded Programming Silberschatz, Galvin and Gagne 2013! Chapter 4: Multithreaded Programming Overview Multicore Programming Multithreading Models Threading Issues Operating System Examples

More information

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

EI 338: Computer Systems Engineering (Operating Systems & Computer Architecture) EI 338: Computer Systems Engineering (Operating Systems & Computer Architecture) Dept. of Computer Science & Engineering Chentao Wu wuct@cs.sjtu.edu.cn Download lectures ftp://public.sjtu.edu.cn User:

More information

Windows NT, Terminal Server and Citrix MetaFrame Terminal Server Architecture

Windows NT, Terminal Server and Citrix MetaFrame Terminal Server Architecture Windows NT, Termina Server and Citrix MetaFrame - CH 3 - Termina Server Architect.. Page 1 of 13 [Figures are not incuded in this sampe chapter] Windows NT, Termina Server and Citrix MetaFrame - 3 - Termina

More information

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

Thread Concept. Thread. No. 3. Multiple single-threaded Process. One single-threaded Process. Process vs. Thread. One multi-threaded Process EECS 3221 Operating System Fundamentals What is thread? Thread Concept No. 3 Thread Difference between a process and a thread Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University

More information

index.pdf March 17,

index.pdf March 17, index.pdf March 17, 2013 1 ITI 1121. Introduction to omputing II Marce Turcotte Schoo of Eectrica Engineering and omputer Science Linked List (Part 2) Tai pointer ouby inked ist ummy node Version of March

More information

Chapter 4: Threads. Operating System Concepts 9 th Edit9on

Chapter 4: Threads. Operating System Concepts 9 th Edit9on Chapter 4: Threads Operating System Concepts 9 th Edit9on Silberschatz, Galvin and Gagne 2013 Chapter 4: Threads 1. Overview 2. Multicore Programming 3. Multithreading Models 4. Thread Libraries 5. Implicit

More information

Chapter 5: Threads. Outline

Chapter 5: Threads. Outline Department of Electr rical Eng ineering, Chapter 5: Threads 王振傑 (Chen-Chieh Wang) ccwang@mail.ee.ncku.edu.tw ncku edu Feng-Chia Unive ersity Outline Overview Multithreading Models Threading Issues 2 Depar

More information

Process. Prepared by Prof. Hui Jiang Dept. of EECS, York Univ. 1. Process in Memory (I) PROCESS. Process. How OS manages CPU usage? No.

Process. Prepared by Prof. Hui Jiang Dept. of EECS, York Univ. 1. Process in Memory (I) PROCESS. Process. How OS manages CPU usage? No. EECS3221.3 Operating System Fundamentals No.2 Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University How OS manages CPU usage? How CPU is used? Users use CPU to run programs

More information

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program?

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program? Intro to Programming & C++ Unit 1 Sections 1.1-3 and 2.1-10, 2.12-13, 2.15-17 CS 1428 Spring 2018 Ji Seaman 1.1 Why Program? Computer programmabe machine designed to foow instructions Program a set of

More information

CS307: Operating Systems

CS307: Operating Systems CS307: Operating Systems Chentao Wu 吴晨涛 Associate Professor Dept. of Computer Science and Engineering Shanghai Jiao Tong University SEIEE Building 3-513 wuct@cs.sjtu.edu.cn Download Lectures ftp://public.sjtu.edu.cn

More information

CS 475. Process = Address space + one thread of control Concurrent program = multiple threads of control

CS 475. Process = Address space + one thread of control Concurrent program = multiple threads of control Processes & Threads Concurrent Programs Process = Address space + one thread of control Concurrent program = multiple threads of control Multiple single-threaded processes Multi-threaded process 2 1 Concurrent

More information

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

Lecture Topics. Announcements. Today: Threads (Stallings, chapter , 4.6) Next: Concurrency (Stallings, chapter , 5. Lecture Topics Today: Threads (Stallings, chapter 4.1-4.3, 4.6) Next: Concurrency (Stallings, chapter 5.1-5.4, 5.7) 1 Announcements Make tutorial Self-Study Exercise #4 Project #2 (due 9/20) Project #3

More information

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

Today s Topics. u Thread implementation. l Non-preemptive versus preemptive threads. l Kernel vs. user threads Today s Topics COS 318: Operating Systems Implementing Threads u Thread implementation l Non-preemptive versus preemptive threads l Kernel vs. user threads Jaswinder Pal Singh Computer Science Department

More information

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

Today s Topics. u Thread implementation. l Non-preemptive versus preemptive threads. l Kernel vs. user threads Today s Topics COS 318: Operating Systems Implementing Threads u Thread implementation l Non-preemptive versus preemptive threads l Kernel vs. user threads Jaswinder Pal Singh and a Fabulous Course Staff

More information

Definition Multithreading Models Threading Issues Pthreads (Unix)

Definition Multithreading Models Threading Issues Pthreads (Unix) Chapter 4: Threads Definition Multithreading Models Threading Issues Pthreads (Unix) Solaris 2 Threads Windows 2000 Threads Linux Threads Java Threads 1 Thread A Unix process (heavy-weight process HWP)

More information

Chapter 4: Threads. Operating System Concepts. Silberschatz, Galvin and Gagne

Chapter 4: Threads. Operating System Concepts. Silberschatz, Galvin and Gagne Chapter 4: Threads Silberschatz, Galvin and Gagne Chapter 4: Threads Overview Multithreading Models Thread Libraries Threading Issues Operating System Examples Linux Threads 4.2 Silberschatz, Galvin and

More information

Chapter 4: Multithreaded

Chapter 4: Multithreaded Chapter 4: Multithreaded Programming Chapter 4: Multithreaded Programming Overview Multithreading Models Thread Libraries Threading Issues Operating-System Examples 2009/10/19 2 4.1 Overview A thread is

More information

Register Allocation. Consider the following assignment statement: x = (a*b)+((c*d)+(e*f)); In posfix notation: ab*cd*ef*++x

Register Allocation. Consider the following assignment statement: x = (a*b)+((c*d)+(e*f)); In posfix notation: ab*cd*ef*++x Register Aocation Consider the foowing assignment statement: x = (a*b)+((c*d)+(e*f)); In posfix notation: ab*cd*ef*++x Assume that two registers are avaiabe. Starting from the eft a compier woud generate

More information

Prepared by Prof. Hui Jiang Process. Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University

Prepared by Prof. Hui Jiang Process. Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University EECS3221.3 Operating System Fundamentals No.2 Process Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University How OS manages CPU usage? How CPU is used? Users use CPU to run

More information

Chapter 4: Threads. Chapter 4: Threads

Chapter 4: Threads. Chapter 4: Threads Chapter 4: Threads Silberschatz, Galvin and Gagne 2013 Chapter 4: Threads Overview Multicore Programming Multithreading Models Thread Libraries Implicit Threading Threading Issues Operating System Examples

More information

Disciplina Sistemas de Computação

Disciplina Sistemas de Computação Aula 09 Disciplina Sistemas de Computação Operating System Roles (recall) OS as a Traffic Cop: Manages all resources Settles conflicting requests for resources Prevent errors and improper use of the computer

More information

Nearest Neighbor Learning

Nearest Neighbor Learning Nearest Neighbor Learning Cassify based on oca simiarity Ranges from simpe nearest neighbor to case-based and anaogica reasoning Use oca information near the current query instance to decide the cassification

More information

What s in a traditional process? Concurrency/Parallelism. What s needed? CSE 451: Operating Systems Autumn 2012

What s in a traditional process? Concurrency/Parallelism. What s needed? CSE 451: Operating Systems Autumn 2012 What s in a traditional process? CSE 451: Operating Systems Autumn 2012 Ed Lazowska lazowska @cs.washi ngton.edu Allen Center 570 A process consists of (at least): An, containing the code (instructions)

More information

Chapter 3: Processes. Operating System Concepts 8th Edition

Chapter 3: Processes. Operating System Concepts 8th Edition Chapter 3: Processes Chapter 3: Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication in Client-Server Systems 3.2 Objectives

More information

Computer Networks. College of Computing. Copyleft 2003~2018

Computer Networks. College of Computing.   Copyleft 2003~2018 Computer Networks Prof. Lin Weiguo Coege of Computing Copyeft 2003~2018 inwei@cuc.edu.cn http://icourse.cuc.edu.cn/computernetworks/ http://tc.cuc.edu.cn Internet Contro Message Protoco (ICMP), RFC 792

More information

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

Last Class: CPU Scheduling. Pre-emptive versus non-preemptive schedulers Goals for Scheduling: CS377: Operating Systems. Last Class: CPU Scheduling Pre-emptive versus non-preemptive schedulers Goals for Scheduling: Minimize average response time Maximize throughput Share CPU equally Other goals? Scheduling Algorithms: Selecting

More information

Lecture 4: Process Management

Lecture 4: Process Management Lecture 4: Process Management (Chapters 2-3) Process: execution context of running program. A process does not equal a program! Process is an instance of a program Many copies of same program can be running

More information

Introduction to OpenMP

Introduction to OpenMP MPSoC Architectures OpenMP Aberto Bosio, Associate Professor UM Microeectronic Departement bosio@irmm.fr Introduction to OpenMP What is OpenMP? Open specification for Muti-Processing Standard API for defining

More information

CS510 Operating System Foundations. Jonathan Walpole

CS510 Operating System Foundations. Jonathan Walpole CS510 Operating System Foundations Jonathan Walpole The Process Concept 2 The Process Concept Process a program in execution Program - description of how to perform an activity instructions and static

More information

CISC2200 Threads Spring 2015

CISC2200 Threads Spring 2015 CISC2200 Threads Spring 2015 Process We learn the concept of process A program in execution A process owns some resources A process executes a program => execution state, PC, We learn that bash creates

More information

Chapter 4: Threads. Chapter 4: Threads

Chapter 4: Threads. Chapter 4: Threads Chapter 4: Threads Silberschatz, Galvin and Gagne 2009 Chapter 4: Threads Overview Multithreading Models Thread Libraries Threading Issues Operating System Examples Windows XP Threads Linux Threads 4.2

More information

Distributed Systems Operation System Support

Distributed Systems Operation System Support Hajussüsteemid MTAT.08.009 Distributed Systems Operation System Support slides are adopted from: lecture: Operating System(OS) support (years 2016, 2017) book: Distributed Systems: Concepts and Design,

More information

Arvind Krishnamurthy Spring Threads, synchronization, scheduling Virtual memory File systems Networking

Arvind Krishnamurthy Spring Threads, synchronization, scheduling Virtual memory File systems Networking Concurrency Arvind Krishnamurthy Spring 2004 Today s lecture Semester roughly divided into: Threads, synchronization, scheduling Virtual memory File systems Networking Next 2.5 weeks: threads and synchronization

More information

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

OPERATING SYSTEMS. UNIT II Sections A, B & D. An operating system executes a variety of programs: OPERATING SYSTEMS UNIT II Sections A, B & D PREPARED BY ANIL KUMAR PRATHIPATI, ASST. PROF., DEPARTMENT OF CSE. PROCESS CONCEPT An operating system executes a variety of programs: Batch system jobs Time-shared

More information

Chapter 3 Process Description and Control

Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles Chapter 3 Process Description and Control Seventh Edition By William Stallings Process Control Block Structure of Process Images in Virtual Memory How

More information

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

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto Ricardo Rocha Department of Computer Science Faculty of Sciences University of Porto Slides based on the book Operating System Concepts, 9th Edition, Abraham Silberschatz, Peter B. Galvin and Greg Gagne,

More information

Chapter 4: Threads. Operating System Concepts 8 th Edition,

Chapter 4: Threads. Operating System Concepts 8 th Edition, Chapter 4: Threads, Silberschatz, Galvin and Gagne 2009 Chapter 4: Threads Overview Multithreading Models Thread Libraries 4.2 Silberschatz, Galvin and Gagne 2009 Objectives To introduce the notion of

More information

Threads. CS3026 Operating Systems Lecture 06

Threads. CS3026 Operating Systems Lecture 06 Threads CS3026 Operating Systems Lecture 06 Multithreading Multithreading is the ability of an operating system to support multiple threads of execution within a single process Processes have at least

More information

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

Chapter 4: Threads. Chapter 4: Threads. Overview Multicore Programming Multithreading Models Thread Libraries Implicit Threading Threading Issues Chapter 4: Threads Silberschatz, Galvin and Gagne 2013 Chapter 4: Threads Overview Multicore Programming Multithreading Models Thread Libraries Implicit Threading Threading Issues 4.2 Silberschatz, Galvin

More information

Lecture 17: Threads and Scheduling. Thursday, 05 Nov 2009

Lecture 17: Threads and Scheduling. Thursday, 05 Nov 2009 CS211: Programming and Operating Systems Lecture 17: Threads and Scheduling Thursday, 05 Nov 2009 CS211 Lecture 17: Threads and Scheduling 1/22 Today 1 Introduction to threads Advantages of threads 2 User

More information

System Call. Preview. System Call. System Call. System Call 9/7/2018

System Call. Preview. System Call. System Call. System Call 9/7/2018 Preview Operating System Structure Monolithic Layered System Microkernel Virtual Machine Process Management Process Models Process Creation Process Termination Process State Process Implementation Operating

More information

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

Processes and Threads. Processes and Threads. Processes (2) Processes (1) Processes and Threads (Topic 2-1) 2 홍성수 Processes and Threads Question: What is a process and why is it useful? Why? With many things happening at once in a system, need some way of separating them all

More information

Process a program in execution; process execution must progress in sequential fashion. Operating Systems

Process a program in execution; process execution must progress in sequential fashion. Operating Systems Process Concept An operating system executes a variety of programs: Batch system jobs Time-shared systems user programs or tasks 1 Textbook uses the terms job and process almost interchangeably Process

More information

Chapter 5: Threads. Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads Java Threads

Chapter 5: Threads. Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads Java Threads Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads Java Threads 5.1 Silberschatz, Galvin and Gagne 2003 More About Processes A process encapsulates

More information

Chapter 4: Multithreaded Programming. Operating System Concepts 8 th Edition,

Chapter 4: Multithreaded Programming. Operating System Concepts 8 th Edition, Chapter 4: Multithreaded Programming, Silberschatz, Galvin and Gagne 2009 Chapter 4: Multithreaded Programming Overview Multithreading Models Thread Libraries Threading Issues 4.2 Silberschatz, Galvin

More information