Lecture 7: Process & Thread Introduction

Similar documents
CSCI 5828: Foundations of Software Engineering

Processes & Threads. Concepts: processes - units of sequential execution.

Chapter 2. Processes & Threads. Concurrency: processes & threads 1. Magee/Kramer

CS 455: INTRODUCTION TO DISTRIBUTED SYSTEMS [THREADS] Frequently asked questions from the previous class survey

CS455: Introduction to Distributed Systems [Spring 2019] Dept. Of Computer Science, Colorado State University

Lecture 9: Introduction to Monitors

Concurrent processes. Processes and Threads. Processes and threads. Going back to Concurrency. Modelling Processes. Modeling processes

CIS233J Java Programming II. Threads

CS 5523 Operating Systems: Midterm II - reivew Instructor: Dr. Tongping Liu Department Computer Science The University of Texas at San Antonio

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

CS 556 Distributed Systems

MultiThreading. Object Orientated Programming in Java. Benjamin Kenwright

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

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

CMSC 433 Programming Language Technologies and Paradigms. Concurrency

Model Requirements and JAVA Programs MVP 2 1

Multi-threaded programming in Java

Advanced Programming Methods. Lecture 6 - Concurrency in Java (1)

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

Threads Chapter 4. Reading: 4.1,4.4, 4.5

Multitasking Multitasking allows several activities to occur concurrently on the computer. A distinction is usually made between: Process-based multit

Chapter 4 Threads, SMP, and

CS 351 Design of Large Programs Threads and Concurrency

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

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

CPS221 Lecture: Threads

Implementation Alternatives. Lecture 2: Implementation Alternatives & Concurrent Programming. Current Implementation Alternatives

Contents. G53SRP: Java Threads. Definition. Why we need it. A Simple Embedded System. Why we need it. Java Threads 24/09/2009 G53SRP 1 ADC

Threaded Programming. Lecture 1: Concepts

Parallel Programming Languages COMP360

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

Java s Implementation of Concurrency, and how to use it in our applications.

Object Oriented Programming. Week 10 Part 1 Threads

Concurrent Programming using Threads

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

Processes, Threads and Processors

Java Threads and intrinsic locks

Last 2 Classes: Introduction to Operating Systems & C++ tutorial. Today: OS and Computer Architecture

Concurrent Programming

Concurrent Programming. Implementation Alternatives. Content. Real-Time Systems, Lecture 2. Historical Implementation Alternatives.

Concurrency: State Models & Design Patterns

CS 450 Operating System Week 4 Lecture Notes

CSE398: Network Systems Design

What is a thread anyway?

CS510 Operating System Foundations. Jonathan Walpole

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

CSCD 330 Network Programming

User Space Multithreading. Computer Science, University of Warwick

Contents. 6-1 Copyright (c) N. Afshartous

Processes and More. CSCI 315 Operating Systems Design Department of Computer Science

Overview of Java Threads (Part 3)

Threads. Definitions. Process Creation. Process. Thread Example. Thread. From Volume II

Introduction to Asynchronous Programming Fall 2014

Lecture 1. CMSC 412 S17 (lect 1)

Four Components of a Computer System. Operating System Concepts 7 th Edition, Jan 12, 2005

Lecture 10: Introduction to Semaphores

Java Threads. Introduction to Java Threads

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

Interfaces. Interfaces. Implementing Interfaces. Interfaces : : : :

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

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

COMP 150-CCP Concurrent Programming. Lecture 12: Deadlock. Dr. Richard S. Hall

1/16/17. Computer Programs and Processes. PHYSICAL: damage from either tampering, misuse, theft of equipment, or any combination of these

Processes. Process Concept

آنستیتیوت تکنالوجی معلوماتی و مخابراتی ICTI

CISC2200 Threads Spring 2015

SUMMARY INTRODUCTION CONCURRENT PROGRAMMING THREAD S BASICS. Introduction Thread basics. Thread states. Sequence diagrams

Synchronization Lecture 24 Fall 2018

CSci 4061 Introduction to Operating Systems. (Thread-Basics)

Chapter 4: Multithreaded

Java Threads. Written by John Bell for CS 342, Spring 2018

Introduction to Threads

Operating Systems (2INC0) 2018/19. Introduction (01) Dr. Tanir Ozcelebi. Courtesy of Prof. Dr. Johan Lukkien. System Architecture and Networking Group

I/O Systems. 04/16/2007 CSCI 315 Operating Systems Design 1

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

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

CS 43: Computer Networks. 07: Concurrency and Non-blocking I/O Sep 17, 2018

Real-Time and Concurrent Programming Lecture 6 (F6): Scheduling and bounded response times

Chapter 3 Process Description and Control

Overview. Processes vs. Threads. Computation Abstractions. CMSC 433, Fall Michael Hicks 1

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

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

CS 351 Design of Large Programs Singleton Pattern

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

Lecture 35. Threads. Reading for next time: Big Java What is a Thread?

Concurrent Programming Lecture 10

COMP31212: Concurrency A Review of Java Concurrency. Giles Reger

7. MULTITHREDED PROGRAMMING

Processes The Process Model. Chapter 2. Processes and Threads. Process Termination. Process Creation

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

COMP 401 ANIMATION, THREADS, COMMAND OBJECTS. Instructor: Prasun Dewan

COMP SCI 3SH3: Operating System Concepts (Term 2 Winter 2006) Test 2 February 27, 2006; Time: 50 Minutes ;. Questions Instructor: Dr.

Lecture 6B Hierarchical/Concurrent State Machine Models (HCFSM)

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

Che-Wei Chang Department of Computer Science and Information Engineering, Chang Gung University

Threads (light weight processes) Chester Rebeiro IIT Madras

COMP 322: Fundamentals of Parallel Programming

Processes and Threads

Scheduler Activations. Including some slides modified from Raymond Namyst, U. Bordeaux

Overview of Java Threads (Part 2)

Transcription:

COMP 150-CCP Concurrent Programming Lecture 7: Process & Thread Introduction Dr. Richard S. Hall rickhall@cs.tufts.edu Concurrent programming February 7, 2008

Operating System Concepts Definition of a process An executing program Similar to an FSP process (i.e., a set of actions that cause state transformations) A conceptual bookkeeping unit for the OS, is used to keep track of Program counter Keeps track of the next instruction to execute All CPU register contents Call stack Open files Memory (including actual program text/code) Any other resources owned by the process program counter CPU register values memory (data and text) open files... call stack

Operating System Concepts Reinterpreting the previous slide, the notion of a process actually embodies two distinct concepts Resource ownership Flow of execution

Operating System Concepts Assume that we divide a process into two pieces A resource container An execution flow After making this division, we name the resource container a process and the execution flow a thread A thread cannot exist without a process, thus a process is also a container for threads A process may contain multiple threads A process with a single thread is equivalent to our original definition of a process

Operating System Concepts The new process contains resources shared by all its threads, whereas the thread contains its own private resources program counter CPU register values memory (data and text) open files... call stack Original process memory (data and text) open files... New process program counter value CPU register values call stack Thread

Operating System Concepts Process/thread relationship Process contains threads Threads share process resources Process memory (data and text) open files... program counter value program counter value CPU program register counter values value CPU program register counter values value CPU program register counter values value call CPU stack register values call CPU stack register values call stack call stack call stack Threads

Operating System Concepts Why do we want threads? Performance multi-processor machines Responsiveness user interfaces Efficiency blocking calls Naturalness related, but separate activity streams

Operating System Concepts Technical benefits of threads 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 Since threads within the same process share memory and files, they can communicate with each other without invoking the kernel

Threading Example Implementing a web server in a single process Three possible approaches Single thread No parallelism, service only one client request at a time Finite state machine Parallelism, requires the use of nonblocking system calls, interrupts As we know, we can simulate multiple threads of controls using a finite state machine, but we no longer have a sequential process, so it is much more complicated to implement Multiple threads Parallelism with simple blocking system calls

Relationship to FSP Modeling processes as finite state machines using FSP/LTS. Implementing processes as threads in Java. To avoid confusion, the term process is used when referring to models, and thread when referring to an implementation in Java.

Java Thread Class java.lang.thread Represents an execution flow Can create new threads dynamically using standard object-oriented approach (i.e., new Thread();) A thread can execute arbitrary code So, how do we tell it which code to execute?

Threads in Java A Thread class manages a single sequential thread of control. Threads may be created and deleted dynamically. Thread run() MyThread run() class MyThread extends Thread { public void run() { //... } } The Thread class executes instructions from its method run(). The actual code executed depends on the implementation provided for run() in a derived class.

Threads in Java Since Java does not permit multiple inheritance, we often implement the run() method in a class not derived from Thread but from the interface Runnable. Runnable target Thread run() MyRun run() public interface Runnable { public abstract void run(); } class MyRun implements Runnable { public void run() { // } }

Thread Subclass vs Runnable A Runnable is potentially more re-usable since other pieces of the Java class library also use the Runnable interface A Runnable does not "waste" inheritance Runnable may promote better design Separation of concerns a thread is a flow of execution that executes some set of actions This creates a Thread/Runnable distinction where the Thread is the flow of execution and the Runnable is the set of actions