Foundations and Definitions

Slides:



Advertisements
Similar presentations
Chapter 6: Process Synchronization
Advertisements

1 CSC321 §2 Concurrent Programming Abstraction & Java Threads Section 2 Concurrent Programming Abstraction & Java Threads.
Threads, SMP, and Microkernels Chapter 4. Process Resource ownership - process is allocated a virtual address space to hold the process image Scheduling/execution-
Lecture 4 Thread Concepts. Thread Definition A thread is a lightweight process (LWP) which accesses a shared address space provided by by the parent process.
Concurrency.
Processes CSCI 444/544 Operating Systems Fall 2008.
3.5 Interprocess Communication
 2004 Deitel & Associates, Inc. All rights reserved. Chapter 4 – Thread Concepts Outline 4.1 Introduction 4.2Definition of Thread 4.3Motivation for Threads.
Multithreading in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Process Management. Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication.
Lecture 2 Foundations and Definitions Processes/Threads.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-1 Process Concepts Department of Computer Science and Software.
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.
 2004 Deitel & Associates, Inc. All rights reserved. 1 Chapter 4 – Thread Concepts Outline 4.1 Introduction 4.2Definition of Thread 4.3Motivation for.
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
C o n f i d e n t i a l 1 Course: BCA Semester: III Subject Code : BC 0042 Subject Name: Operating Systems Unit number : 1 Unit Title: Overview of Operating.
Processes and Process Control 1. Processes and Process Control 2. Definitions of a Process 3. Systems state vs. Process State 4. A 2 State Process Model.
Multithreading in Java Sameer Singh Chauhan Lecturer, I. T. Dept., SVIT, Vasad.
Chapter 2 Processes and Threads Introduction 2.2 Processes A Process is the execution of a Program More specifically… – A process is a program.
CPS110: Implementing threads Landon Cox. Recap and looking ahead Hardware OS Applications Where we’ve been Where we’re going.
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
Java Thread and Memory Model
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
Department of Computer Science and Software Engineering
Concurrency Properties. Correctness In sequential programs, rerunning a program with the same input will always give the same result, so it makes sense.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Processes and Threads.
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
Chapter 2 Process Management. 2 Objectives After finish this chapter, you will understand: the concept of a process. the process life cycle. process states.
What is a Process ? A program in execution.
Operating Systems Unit 2: – Process Context switch Interrupt Interprocess communication – Thread Thread models Operating Systems.
1 Critical Section Problem CIS 450 Winter 2003 Professor Jinhua Guo.
Introduction to operating systems What is an operating system? An operating system is a program that, from a programmer’s perspective, adds a variety of.
Threads, SMP, and Microkernels Chapter 4. Processes and Threads Operating systems use processes for two purposes - Resource allocation and resource ownership.
Advanced Operating Systems CS6025 Spring 2016 Processes and Threads (Chapter 2)
1 Module 3: Processes Reading: Chapter Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3.
Tutorial 2: Homework 1 and Project 1
Multiprogramming. Readings r Chapter 2.1 of the textbook.
Introduction to Operating Systems Concepts
Chapter 4 – Thread Concepts
Processes and threads.
Process concept.
Process Management Process Concept Why only the global variables?
Chapter 3: Process Concept
CS 6560: Operating Systems Design
OPERATING SYSTEMS CS3502 Fall 2017
Concurrency, Processes and Threads
Chapter 4 – Thread Concepts
CS399 New Beginnings Jonathan Walpole.
Process Management Presented By Aditya Gupta Assistant Professor
Chapter 4 Threads.
Intro to Processes CSSE 332 Operating Systems
Threads & multithreading
Threads, SMP, and Microkernels
Chapter 15, Exploring the Digital Domain
COT 5611 Operating Systems Design Principles Spring 2014
System Structure and Process Model
CSE 451: Operating Systems Spring 2012 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Process & its States Lecture 5.
Thread Implementation Issues
Lecture Topics: 11/1 General Operating System Concepts Processes
Lecture 4- Threads, SMP, and Microkernels
Threads Chapter 4.
Processes Hank Levy 1.
Chapter 3: Processes.
CS510 Operating System Foundations
CSE 153 Design of Operating Systems Winter 2019
Processes Hank Levy 1.
Concurrency, Processes and Threads
Chapter 3: Process Management
Presentation transcript:

Foundations and Definitions Lecture 2 Foundations and Definitions Processes/Threads

The Role of Abstraction It is convenient and sometimes necessary to limit our view to one level of detail In Software Engineering with typically deal with three levels of abstraction Systems and Libraries Programming Languages Instruction Sets The two most important tools for SW abstraction are encapsulation and concurrency

Definitions

A Simple Example

Programs in a Language-Independent Form

Definitions

Scenarios

Multitasking Systems Multitasking is the process of sharing the resources of one computer with multiple processes. A process called an interrupt handler deals with I/O interrupts. Once a process is interrupted the OS scheduler may decide which process is to execute next. As shown in the diagram four concurrently executing programs are sharing the computer with the OS. When a process is interrupted its register values are saved in memory and the register values for the interrupting process are loaded. This is called a context switch. At the conclusion of the interrupt processing, the symmetric context switch is performed storing the interrupt handler registers and loading the registers for another program (usually but not necessarily the program that was interrupted).

Multiprocessing Systems

The Issue of Contention for Global Memory

Distributed Systems

Topology affects Efficiency

Atomic Statements Atomic statements are those that, once started, cannot be interrupted before completion. In the abstract world of concurrency examples are: Assignment statements Boolean conditional statements Unfortunately this assumption is not realistic. In a real computer atomic statements are the machine statements generated by the language compiler. On statement in a high-level language may become several machine language statements. We will continue to use high-level language pseudocode in our example programs and we will assume they are atomic while we understand that this may not be true.

Correctness and Concurrency Each time we run a sequential program with the same input we expect and get the same result. So program debugging involves running the program, checking for and fixing errors until the problem has been eliminated. We cannot expect to debug concurrent programs in this manner. Due to arbitrary interleaving of statements we are unlikely to get the same answer twice even with the same input when there is a problem with our program. In concurrent programs we are interested in the properties of correctness. There are two types of correctness properties: Safety properties – the property must always be true Liveness properties – the property must eventually become true. Often a safety property is of the form “some bad thing is always not true”. In addition, safety properties and liveness properties are duals of one another.

Volatile and Non-Atomic Variables

What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently, each as a distinct entity with its own state. The process state consists of at least: the code for the running program the static data for running program a space in the heap for dynamic data the address of next instruction execution stack values of the CPU registers OS resources (e.g. open filees) process execution state Computer Memory Process Code

Process State Each process transitions from one state to the next as it shares the CPU and additional computer resources with other processes. A process changes states due to actions by the OS and other entities. Terminated New

Suspend & Resume Suspending a process indefinitely removes it from contention for time on a processor without being destroyed. Suspending a process is useful for detecting security threats and for software debugging purposes (e.g. deadlock detection and recovery). A suspension may be initiated by the process being suspended or by another process.

Thread Definition A thread is a lightweight process (LWP) which accesses a shared address space provided by by the parent process. Each thread keeps its own state parameters and register values so that it may run concurrently with other threads. Threads may be managed by the OS (kernel-level threads) or by a user application (user-level threads). 2004 Deitel & Associates, Inc.

Threads vs. Processes Processes each have their own address space, text space and resources, while threads spawned within a user application all share the memory and resources of the parent thread or process. A thread defines a single sequential execution stream within a process. Each thread maintains its own PC, SP and CPU register values.

Thread States 2004 Deitel & Associates, Inc.

Thread Operations Threads have some operations in common with processes Create Exit (terminate) Suspend Resume Sleep Wake Other thread operations do not correspond to process operations Cancel - indicates that a thread should be terminated, but does not guarantee that the thread will be terminated. Threads can mask the cancellation signal. Join - a primary thread can wait for all other threads to exit by joining them. The joining thread blocks until the thread it joined exits. 2004 Deitel & Associates, Inc.

User-Level Threads A user-level thread is one that is created and managed by a user application. Usually the OS does not know of the existence of user-level threads so additional resources are not provided by the OS for user-level threads. Each user-level thread must share the resources already allocated to the user application. 2004 Deitel & Associates, Inc.

Kernel-Level Threads Kernel-level threads are created and managed by the OS. They attempt to address the limitations of user-level threads by mapping each thread to its own execution context. Kernel-level threads offer increased scalability, interactivity, and throughput, but have a higher overhead due to context switching and reduced portability because of OS-specific APIs 2004 Deitel & Associates, Inc.

A Simple Multi-Threading Demo using System; using System.Threading; namespace first_thread_demo { public class Version_1 public static bool done = false; public static void T1() System.Random rnd = new Random(); while (!done) Console.WriteLine("T1 in critical section"); Thread.Sleep(rnd.Next(100)); Console.WriteLine("T1 is leaving critical section"); } static void Main(string[] args) Thread p = new Thread(new ThreadStart(T1)); p.Start(); Thread q = new Thread(new ThreadStart(T2)); q.Start(); Thread.Sleep(5000); done = true; Console.WriteLine("Run Finished"); Console.ReadKey(); public static void T2() { System.Random rnd = new Random(); while (!done) Console.WriteLine("T2 in critical section"); Thread.Sleep(rnd.Next(100)); Console.WriteLine("T2 is leaving critical section"); }

BothT1 & T2 can be in Critical Sections at the Same Time T2 is leaving critical section T2 in critical section T1 is leaving critical section T1 in critical section

A "Fix" for the Problem The inclusion of a globally accessible variable threadnumber that can be set to the number of the preferred thread to execute can prevent two threads from entering their critical sections at the same time, but at what cost? public static int threadnumber = 1; : public static void T1() { System.Random rnd = new Random(); while (!done) while (threadnumber == 2); Console.WriteLine("T1 in critical section"); Thread.Sleep(rnd.Next(100)); Console.WriteLine("T1 is leaving critical section"); threadnumber = 2; } a very important semicolon