Operating Systems. Lecture 4. Nachos Appetizer

Similar documents
Chapter 3 Process Description and Control

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

Threads Chapter 5 1 Chapter 5

Threads. CS3026 Operating Systems Lecture 06

Processes and Threads. Processes: Review

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

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

CSE 306/506 Operating Systems Threads. YoungMin Kwon

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

4. Concurrency via Threads

Operating System 4 THREADS, SMP AND MICROKERNELS

Lecture 4: Threads; weaving control flow

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

ECE519 Advanced Operating Systems

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

Threads Chapter 4. Reading: 4.1,4.4, 4.5

CSE 120 Principles of Operating Systems

CSE 120 Principles of Operating Systems

Chapter 4 Threads, SMP, and

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

Threads, SMP, and Microkernels

Processes and Threads

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

CSE 120 Principles of Operating Systems

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

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

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

Processes, Threads, SMP, and Microkernels

Threads. Threads (continued)

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

CSE 153 Design of Operating Systems Fall 2018

Process Description and Control

Process Characteristics

Processes and Non-Preemptive Scheduling. Otto J. Anshus

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

CSCE 313: Intro to Computer Systems

Chapter 5: Threads. Outline

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

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

CS 31: Intro to Systems Threading & Parallel Applications. Kevin Webb Swarthmore College November 27, 2018

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

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

Processes. CS3026 Operating Systems Lecture 05

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

CSE 153 Design of Operating Systems Fall 2018

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

Process Description and Control

THREADS. Jo, Heeseung

CS 153 Design of Operating Systems Winter 2016

Threads (light weight processes) Chester Rebeiro IIT Madras

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

OPERATING SYSTEM. Chapter 4: Threads

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

CS510 Operating System Foundations. Jonathan Walpole

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

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

Computer Systems Laboratory Sungkyunkwan University

1 System & Activities

CS333 Intro to Operating Systems. Jonathan Walpole

Processes and Threads

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

CS 326: Operating Systems. Process Execution. Lecture 5

What s in a process?

From Processes to Threads

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

W4118 Operating Systems. Junfeng Yang

Agenda. Threads. Single and Multi-threaded Processes. What is Thread. CSCI 444/544 Operating Systems Fall 2008

Processes and Threads. From Processes to Threads. The Case for Threads. The Case for Threads. Process abstraction combines two concepts.

Fall 2017 :: CSE 306. Introduction to. Virtual Memory. Nima Honarmand (Based on slides by Prof. Andrea Arpaci-Dusseau)

Operating System Architecture. CS3026 Operating Systems Lecture 03

Mon Sep 17, 2007 Lecture 3: Process Management

CSI3131 Final Exam Review

Sistemi in Tempo Reale

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

CISC2200 Threads Spring 2015

Chapter 4: Multithreaded Programming

Threads and Too Much Milk! CS439: Principles of Computer Systems January 31, 2018

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

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

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

Chapter 4: Threads. Chapter 4: Threads

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

CS140 Operating Systems and Systems Programming Midterm Exam

!! How is a thread different from a process? !! Why are threads useful? !! How can POSIX threads be useful?

Threads and Too Much Milk! CS439: Principles of Computer Systems February 6, 2019

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Processes and threads

Processes. OS Structure. OS Structure. Modes of Execution. Typical Functions of an OS Kernel. Non-Kernel OS. COMP755 Advanced Operating Systems

Agenda Process Concept Process Scheduling Operations on Processes Interprocess Communication 3.2

From Processes to Threads

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

Lecture 4: Process Management

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

CS 318 Principles of Operating Systems

殷亚凤. Processes. Distributed Systems [3]

Thread. Disclaimer: some slides are adopted from the book authors slides with permission 1

Lecture 5: Process Description and Control Multithreading Basics in Interprocess communication Introduction to multiprocessors

Concurrency, Thread. Dongkun Shin, SKKU

SMD149 - Operating Systems

Processes and Threads

QUESTION BANK UNIT I

Transcription:

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) switch is pure overhead

Process Characterization Process has two characteristics: 1. resource ownership address space to hold process image I/O devices, files, etc. 2. execution a single execution path (thread of control) execution state, PC & registers, stack

Refining Terminology Distinguish the two characteristics process: resource ownership thread: unit of execution (dispatching) AKA lightweight process (LWP) Multi-threading: threading: support multiple threads of execution within a single process Process, as we have known it thus far, is a single-threaded process

Single- vs. Multi-threaded threaded Model

Multi-Threaded Environment Process: virtual address space (for image) protected access to resources processors, other processes, I/O, files Thread: one or more w/in a process execution state saved context when not running (i.e., independent PC) stack access to memory & resources of the process

Multi-Threaded Environment Left: shared by all threads in a process Right: private to each thread

Single- vs. Multi-threaded Model still a single PCB & addr space per process separate stacks, TCB for each thread

Single- vs. Multi-threaded Model

Remember Different threads in a process have same address space Every thread can access every mem addr w/in addr space No protection between threads Each thread has its own stack one frame per procedure called but not completed (local vars, return address)

Why Threads? In many apps, multiple activities @ once e.g., word processor Easier to create and destroy than processes no resources attached to threads Allow program to continue if part is blocked permit I/O- and CPU-bound activities to overlap speeds up application Easy resource sharing (same addr space!) Take advantage of multiprocessors

Some Examples word processor Web server handle interrupts

Thread Functionality Scheduling done on a per-thread basis Terminate process --> kill all threads Four basic thread operations: spawn (automatically spawned for new process) block unblock terminate Synchronization: all threads share same addr space & resources must synchronize to avoid conflicts process synchro techniques are same for threads (later)

Two Types Of Threads User-Level Kernel-Level e e e

User-Level Threads Thread management done by an application Use thread library (e.g., POSIX Pthreads) create/destroy, pass msgs, schedule execution, save/restore contexts Each process needs its own thread table Kernel is unaware of these threads assigns single execution state to the process unaware of any thread scheduling activity

User-Level Threads Advantages: thread switch does not require kernel privileges thread switch more efficient than kernel call scheduling can be process (app) specific without disturbing OS can run on any OS scales easily Disadvantages: if one thread blocks, all are blocked (process switch) e.g., I/O, page faults cannot take advantage of multiprocessor one process to one processor programmers usually want threads for blocking apps

Kernel-Level Threads Thread management done by kernel process as a whole (process table) individual threads (thread table) Kernel schedules on a per-thread basis Addresses disadvantages d of ULT: schedule multi threads from one process on multiple CPUs if one thread blocks, schedule another (no process switch) Disadvantage of KLT: thread switch causes mode switch to kernel

What is (not are) Nachos? Not Another Completely Heuristic Operating System Non-trivial instructional software You modify, develop, and execute actual OS code! Supports: threads user-level processes (you will write your own!) virtual memory file systems etc.

Your First Nachos Project Build a Thread System A partial system is given to you: thread fork thread completion semaphores for synchronization (huh?) for concurrency issues (to come) Your job: first, read and understand d the code as given second, implement additional synchro routines finally, implement specific problems that use your routines

At This Point, You Should Download nachos1.tgz to your directory To extract: tar -xzvf nachos1.tgz See man tar Resulting nachos1/ directory will contain: Makefile, Makefile.common, Makefile.dep threads/ directory machine/ directory Print out all the.cc and.h files highlight, make notes, etc.

At This Point, You Should Read, read, read! Read the Roadmap sections Nachos Machine Nachos Threads If you want to trace execution, find main() A great searching utility: grep grep main threads/*.cc grep main machine/*.cc Quiz next Thursday on this reading Quiz next Thursday on this reading specifically focus on Nachos Threads

Want to run Nachos? Execute make in nachos1/ directory The executable nachos resides in threads/ cd dthreads/./nachos Then, watch the magic! actually, not very exciting at this point Trace through your hardcopies of the code